网站开发页面怎么进,代做机械设计的网站,wordpress非凡主题里导航下拉菜单,网站建设是怎么挣钱的TrackerEasyswoole提供了一个基础的追踪组件#xff0c;方便用户实现基础的服务器状态监控#xff0c;与调用链记录。组件要求php: 7.1.0ext-swoole: ^4.4.0easyswoole/component: ^2.0安装方法composer require easyswoole/tracker仓库地址调用链Easyswoole的调用链跟踪…TrackerEasyswoole提供了一个基础的追踪组件方便用户实现基础的服务器状态监控与调用链记录。组件要求php: 7.1.0ext-swoole: ^4.4.0easyswoole/component: ^2.0安装方法composer require easyswoole/tracker仓库地址调用链Easyswoole的调用链跟踪是一个以类似有序的树状链表的解构实现的解构如下struct Point{struct Point* nextPoint;struct Point[] subPoints;const END_SUCCESS success;const END_FAIL fail;const END_UNKNOWN unknown;int startTime;mixed startArg;int endTime;string pointName;string endStatus self::END_UNKNOWN;mixed endArg;string pointId;string parentId;int depth 0;bool isNext}基本使用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,accessLogIdlogIdxxxxxxxxxx]);//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,[failMsgtimeout]);$waitGroup-done();});$waitGroup-wait();$actionOne-end();//actionOne结束进入afterAction$afterAction $actionOne-next(afterAction);//模拟响应记录\co::sleep(0.01);$afterAction-end($afterAction::END_SUCCESS,[logsuccess]);/** 从入口开始打印调用链*/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,accessLogIdlogIdxxxxxxxxxx])-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,[failMsgtimeout]);$waitGroup-done();});$waitGroup-wait();PointContext::getInstance()-find(actionOne)-end();//模拟响应记录\co::sleep(0.01);PointContext::getInstance()-find(afterAction)-end(Point::END_SUCCESS,[logsuccess]);/** 从入口开始打印调用链*/echo Point::toString(PointContext::getInstance()-startPoint());});以上代码输出结果#PointName:onRequestStatus:successPointId:AoRVFMgrsbNwukBZc7Depth:0IsNext:falseStart:1561736477.2808StartArg:{requestArg:requestArgxxxxxxxx,accessLogId:logIdxxxxxxxxxx}End:1561736477.2939EndArg:nullChildCount:0Children:NoneNextPoint:#PointName:actionOneStatus:successPointId:2zOWG1SvMbyBcnRmjeDepth:0IsNext:trueStart:1561736477.2809StartArg:nullEnd:1561736478.2993EndArg:nullChildCount:2Children:#PointName:subOneStatus:successPointId:0wU31l8brpfCnXdTxHDepth:1IsNext:falseStart:1561736477.2939StartArg:nullEnd:1561736477.4006EndArg:nullChildCount:0Children:NoneNextPoint:None#PointName:subTwoStatus:failPointId:Jphr6RD8KSHmYbt70ADepth:1IsNext:falseStart:1561736477.2939StartArg:nullEnd:1561736478.2993EndArg:{failMsg:timeout}ChildCount:0Children:NoneNextPoint:NoneNextPoint:#PointName:afterActionStatus:successPointId:oPnGNrkj6qwb381BQlDepth:0IsNext:trueStart:1561736477.2809StartArg:nullEnd:1561736478.3119EndArg:{log:success}ChildCount:0Children:NoneNextPoint:None如果想以自己的格式记录到数据库可以具体查看Point实现的方法每个Point都有自己的Id进阶使用HTTP API请求追踪EasySwooleEvent.phpnamespace EasySwoole\EasySwoole;use EasySwoole\EasySwoole\Swoole\EventRegister;use EasySwoole\EasySwoole\AbstractInterface\Event;use EasySwoole\Http\Request;use EasySwoole\Http\Response;use EasySwoole\Tracker\Point;use EasySwoole\Tracker\PointContext;class EasySwooleEvent implements Event{public static function initialize(){// TODO: Implement initialize() method.date_default_timezone_set(Asia/Shanghai);}public static function mainServerCreate(EventRegister $register){}public static function onRequest(Request $request, Response $response): bool{$point PointContext::getInstance()-createStart(onRequest);$point-setStartArg([uri$request-getUri()-__toString(),get$request-getQueryParams()]);return true;}public static function afterRequest(Request $request, Response $response): void{$point PointContext::getInstance()-startPoint();$point-end();echo Point::toString($point);$array Point::toArray($point);}}Index.phpnamespace App\HttpController;use EasySwoole\Component\WaitGroup;use EasySwoole\Http\AbstractInterface\Controller;use EasySwoole\Tracker\PointContext;class Index extends Controller{protected function onRequest(?string $action): ?bool{/** 调用关系 HttpRequest-OnRequest*/$point PointContext::getInstance()-next(ControllerOnRequest);//假设这里进行了权限验证并模拟数据库耗时\co::sleep(0.01);$point-setEndArg([userIdxxxxxxxxxxx]);$point-end();return true;}function index(){//模拟调用第三方Api,调用关系 OnRequest-sub(subApi1,subApi2)$actionPoint PointContext::getInstance()-next(indexAction);$wait new WaitGroup();$subApi $actionPoint-appendChild(subOne);$wait-add();go(function ()use($wait,$subApi){\co::sleep(1);$subApi-end();$wait-done();});$subApi $actionPoint-appendChild(subTwo);$wait-add();go(function ()use($wait,$subApi){\co::sleep(0.3);$subApi-end($subApi::END_FAIL);$wait-done();});$wait-wait();$actionPoint-end();$this-response()-write(hello world);}}以上每次请求会输出如下格式#PointName:onRequestStatus:successPointId:1561743038GyV4lnusParentId:Depth:0IsNext:falseStart:1561743038.7011StartArg:{uri:http://127.0.0.1:9501/,get:[]}End:1561743039.7152EndArg:nullChildCount:0Children:NoneNextPoint:#PointName:ControllerOnRequestStatus:successPointId:15617430386f0OQDsSParentId:1561743038GyV4lnusDepth:0IsNext:trueStart:1561743038.7025StartArg:nullEnd:1561743038.713EndArg:nullChildCount:0Children:NoneNextPoint:#PointName:indexActionStatus:successPointId:1561743038XEmF0M49ParentId:15617430386f0OQDsSDepth:0IsNext:trueStart:1561743038.7131StartArg:nullEnd:1561743039.7151EndArg:nullChildCount:2Children:#PointName:subOneStatus:successPointId:1561743038uIkzYgcSParentId:1561743038XEmF0M49Depth:1IsNext:falseStart:1561743038.7135StartArg:nullEnd:1561743039.7151EndArg:nullChildCount:0Children:NoneNextPoint:None#PointName:subTwoStatus:failPointId:1561743038PslVSY4nParentId:1561743038XEmF0M49Depth:1IsNext:falseStart:1561743038.7136StartArg:nullEnd:1561743039.0149EndArg:nullChildCount:0Children:NoneNextPoint:NoneNextPoint:NoneApi调用链记录$array Point::toArray($point);可以把一个入口点转为一个数组。例如我们可以在MYSQL数据库中存储以下关键结构CREATE TABLE api_tracker_point_list (pointd varchar(18) NOT NULL,pointName varchar(45) DEFAULT NULL,parentId varchar(18) DEFAULT NULL,depth int(11) NOT NULL DEFAULT 0,isNext int(11) NOT NULL DEFAULT 0,startTime varchar(14) NOT NULL,endTime varchar(14) DEFAULT NULL,status varchar(10) NOT NULL,PRIMARY KEY (pointd),UNIQUE KEY trackerId_UNIQUE (pointd)) ENGINEInnoDB DEFAULT CHARSETutf8;其余请求参数可以自己记录。核心字段在pointIdparentId与isNextstatus 这四个个字段,例如我想得到哪次调用链超时那么就是直接where status fail如果想看哪次调用耗时多少那么可以where spendTime 3spendTime 是用startTime和endTime计算相关仓库EasySwoole之链路追踪 简单demo