easyswoole/tracker
Composer 安装命令:
composer require easyswoole/tracker
包简介
easyswoole component
README 文档
README
安装
composer require easyswoole/tracker
追踪器的使用
use EasySwoole\Tracker\Point;
use EasySwoole\Component\WaitGroup;
use EasySwoole\Tracker\PointContext;
/*
* 假设我们的调用链是这样的
* onRequest ->> actionOne ->> actionOne call remote Api(1,2) ->> afterAction
*/
go(function (){
/*
* 创建入口
*/
$onRequest = new Point('onRequest');
//记录请求参数,并模拟access log
\co::sleep(0.01);
$onRequest->setStartArg([
'requestArg' => 'requestArgxxxxxxxx',
'accessLogId'=>'logIdxxxxxxxxxx'
]);
//onRequest完成
$onRequest->end();
//进入 next actionOne
$actionOne = $onRequest->next('actionOne');
//action one 进入子环节调用
$waitGroup = new WaitGroup();
//sub pointOne
$waitGroup->add();
$subOne = $actionOne->appendChild('subOne');
go(function ()use($subOne,$waitGroup){
\co::sleep(0.1);
$subOne->end();
$waitGroup->done();
});
//sub pointTwo,并假设失败
$waitGroup->add();
$subTwo = $actionOne->appendChild('subTwo');
go(function ()use($subTwo,$waitGroup){
\co::sleep(1);
$subTwo->end($subTwo::END_FAIL,['failMsg'=>'timeout']);
$waitGroup->done();
});
$waitGroup->wait();
$actionOne->end();
//actionOne结束,进入afterAction
$afterAction = $actionOne->next('afterAction');
//模拟响应记录
\co::sleep(0.01);
$afterAction->end($afterAction::END_SUCCESS,['log'=>'success']);
/*
* 从入口开始打印调用链
*/
echo Point::toString($onRequest);
});
go(function (){
PointContext::getInstance()->createStart('onRequest')->next('actionOne')->next('afterAction');
//记录请求参数,并模拟access log
\co::sleep(0.01);
PointContext::getInstance()->find('onRequest')->setStartArg([
'requestArg' => 'requestArgxxxxxxxx',
'accessLogId'=>'logIdxxxxxxxxxx'
])->end();
$subOne = PointContext::getInstance()->find('actionOne')->appendChild('subOne');
$subTwo = PointContext::getInstance()->find('actionOne')->appendChild('subTwo');
$waitGroup = new WaitGroup();
$waitGroup->add();
go(function ()use($subOne,$waitGroup){
\co::sleep(0.1);
$subOne->end();
$waitGroup->done();
});
//sub pointTwo,并假设失败
$waitGroup->add();
go(function ()use($subTwo,$waitGroup){
\co::sleep(1);
$subTwo->end($subTwo::END_FAIL,['failMsg'=>'timeout']);
$waitGroup->done();
});
$waitGroup->wait();
PointContext::getInstance()->find('actionOne')->end();
//模拟响应记录
\co::sleep(0.01);
PointContext::getInstance()->find('afterAction')->end(Point::END_SUCCESS,['log'=>'success']);
/*
* 从入口开始打印调用链
*/
echo Point::toString(PointContext::getInstance()->startPoint());
});
协程中可以用 PointContext 来管理创建主节点
以上代码输出
#
PointName:onRequest
Status:success
PointId:AoRVFMgrsbNwukBZc7
Depth:0
IsNext:false
Start:1561736477.2808
StartArg:{"requestArg":"requestArgxxxxxxxx","accessLogId":"logIdxxxxxxxxxx"}
End:1561736477.2939
EndArg:null
ChildCount:0
Children:None
NextPoint:
#
PointName:actionOne
Status:success
PointId:2zOWG1SvMbyBcnRmje
Depth:0
IsNext:true
Start:1561736477.2809
StartArg:null
End:1561736478.2993
EndArg:null
ChildCount:2
Children:
#
PointName:subOne
Status:success
PointId:0wU31l8brpfCnXdTxH
Depth:1
IsNext:false
Start:1561736477.2939
StartArg:null
End:1561736477.4006
EndArg:null
ChildCount:0
Children:None
NextPoint:None
#
PointName:subTwo
Status:fail
PointId:Jphr6RD8KSHmYbt70A
Depth:1
IsNext:false
Start:1561736477.2939
StartArg:null
End:1561736478.2993
EndArg:{"failMsg":"timeout"}
ChildCount:0
Children:None
NextPoint:None
NextPoint:
#
PointName:afterAction
Status:success
PointId:oPnGNrkj6qwb381BQl
Depth:0
IsNext:true
Start:1561736477.2809
StartArg:null
End:1561736478.3119
EndArg:{"log":"success"}
ChildCount:0
Children:None
NextPoint:None
easyswoole/tracker 适用场景与选型建议
easyswoole/tracker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「async」 「swoole」 「easyswoole」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 easyswoole/tracker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 easyswoole/tracker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 easyswoole/tracker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
The bundle for easy using json-rpc api on your project
An async event for hyperf.
annotations-scan-plugin
Zenity allows you to build graphical desktop (GUI) applications in PHP, built on top of ReactPHP.
SForum
统计信息
- 总下载量: 8.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-06-14