如何使用Blackfire剖析PHP Shell脚本应用或工作程序 [英] How to profile a PHP shell script app or worker using Blackfire

查看:352
本文介绍了如何使用Blackfire剖析PHP Shell脚本应用或工作程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I noticed that when I have an endless worker I cannot profile PHP shell scripts. Because when it's killed it doesn't send the probe.

我该怎么做?

推荐答案

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

When you are trying to profile a worker which is running an endless loop. In this case you have to manually edit your code to either remove the endless loop or instrument your code to manually call the close() method of the probe (https://blackfire.io/doc/manual-instrumentation).

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

That's because the data is sent to the agent only when the close() method is called (it is called automatically at the end of the program unless you killed it).

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

You can manually instrument some code by using the BlackfireProbe class that comes bundled with the Blackfire's probe:

// 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实用程序运行代码时,分析才处于活动状态.如果没有,则所有呼叫都将转换为无操作.

As with auto-instrumentation, profiling is only active when the code is run through the Companion or the blackfire CLI utility. If not, all calls are converted to noops.

这篇关于如何使用Blackfire剖析PHP Shell脚本应用或工作程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆