sanprojects/interceptor
Composer 安装命令:
composer require sanprojects/interceptor
包简介
Intercept php functions
README 文档
README
Intercepts external request in php scripts, and log it to STDERR.
So you can better understand what doing your program.
Installation
composer require sanprojects/interceptor
Basic Usage:
// Intercept all kind of requests \Sanprojects\Interceptor\Interceptor::interceptAll();
Now in the console you'll see something like this:
Interceptor.DEBUG: curl -vX POST 'https://www.example.com/' \
--data 'postvar1=value1&postvar2=value2&postvar3=value3'
Interceptor.DEBUG: CURL> <!doctype html> ...
Interceptor.DEBUG: fopen /Users/san/PhpstormProjects/interceptor/tests/test.txt w+b [resource(stream)]
Interceptor.DEBUG: fwrite /Users/san/PhpstormProjects/interceptor/tests/test.txt test 4
Interceptor.DEBUG: fread /Users/san/PhpstormProjects/interceptor/tests/test.txt 100 test
Interceptor.DEBUG: file_put_contents /Users/san/PhpstormProjects/interceptor/tests/test.txt test 4
Interceptor.DEBUG: Redis::__construct NULL
Interceptor.DEBUG: Redis tcp://127.0.0.1:6379 set test {"jsonKey":123} Predis\Response\Status
Interceptor.DEBUG: Redis tcp://127.0.0.1:6379 get test {"jsonKey":123}
Interceptor.DEBUG: mysqli_connect ensembldb.ensembl.org anonymous mysqli
Interceptor.DEBUG: mysqli_query ensembldb.ensembl.org SELECT 123 mysqli_result
Interceptor.DEBUG: PDO::__construct mysql:dbname=;host=ensembldb.ensembl.org anonymous NULL
Interceptor.DEBUG: PDO::query SELECT 123 Sanprojects\Interceptor\Hooks\PDOStatement
Interceptor.DEBUG: PDOStatement::execute SELECT 123; true
How it works
It use stream_wrapper_register to intercept included php files
and stream_filter_register for rewrite source code.
Support
curl, fwrite, fread, file_get_contents, file_put_contents, mysqli, Redis, PDO, AMQP.
Caveats
- It turns off opcache.
- Because of source code injection, it can crush your app. Not all cases tested.
How to inject
Option 1: Run interceptor.phar
curl -O https://sanprojects.github.io/interceptor/interceptor.phar php -d opcache.enable=0 interceptor.phar <yourScript.php>
Option 2: Use auto_prepend_file
curl -O https://sanprojects.github.io/interceptor/interceptor.phar php -d opcache.enable=0 -d auto_prepend_file=interceptor.php <yourScript.php>
Option 1: Include in your script
\Sanprojects\Interceptor\Interceptor::interceptAll();
Option 2: Include php file in your script
require 'vendor/bin/interceptor.php';
Use it only for debug environment.
sanprojects/interceptor 适用场景与选型建议
sanprojects/interceptor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42.17k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2021 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「php」 「curl」 「debug」 「pdo」 「mysqli」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sanprojects/interceptor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sanprojects/interceptor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sanprojects/interceptor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 42.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-15