系统相关
首页 > 系统相关> > 如何使用Blackfire剖析PHP Shell脚本应用或工作程序

如何使用Blackfire剖析PHP Shell脚本应用或工作程序

作者:互联网

我注意到,当我有一个无休止的工作者时,我无法剖析PHP Shell脚本.因为当它被杀死时,它不会发送探针.

我该怎么做?

解决方法:

当您尝试分析正在运行无限循环的工作程序时.在这种情况下,您必须手动编辑代码以消除无限循环或检测代码以手动调用探针(https://blackfire.io/doc/manual-instrumentation)的close()方法.

这是因为仅在调用close()方法时(除非您杀死了它,它才会在程序结束时自动调用)将数据发送到代理.

您可以使用Blackfire探针附带的BlackfireProbe类来手动检测一些代码:

// Get the probe main instance
$probe = BlackfireProbe::getMainInstance();
// start profiling the code
$probe->enable();

// Calling close() instead of disable() stops the profiling and forces the  collected data to be sent to Blackfire:

// stop the profiling
// send the result to Blackfire
$probe->close();

与自动仪器一样,仅当通过Companion或blackfire CLI实用程序运行代码时,分析才处于活动状态.如果不是,则所有呼叫都转换为无操作.

标签:worker,beanstalkd,php,blackfire
来源: https://codeday.me/bug/20191120/2042214.html