× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to profile a PHP shell script app or worker using Blackfire

Nov 18, 2015
<p>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 (<a href="https://blackfire.io/doc/manual-instrumentation" rel="nofollow">https://blackfire.io/doc/manual-instrumentation</a>).</p> <p>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).</p> <p>You can manually instrument some code by using the BlackfireProbe class that comes bundled with the Blackfire's probe:</p> <pre><code>// Get the probe main instance $probe = BlackfireProbe::getMainInstance(); // start profiling the code $probe-&gt;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-&gt;close(); </code></pre> <p>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.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30645598/How%20to%20profile%20a%20PHP%20shell%20script%20app%20or%20worker%20using%20Blackfire/30645616">Stack Overflow</a>.</p>
comments powered by Disqus