Blackfire: A better Experience for XHProf Users
If XHProf is already installed on your infrastructure, you might want to try Blackfire without replacing XHProf by the Blackfire PHP extension.
If you are a regular XHProf user, but don’t have time to try Blackfire, you can easily benefit from some Blackfire unique features like the UI and the browser extension.
We’ve just open-sourced the PHP code that we are using to prototype new features for the Blackfire’s PHP extension (the code is also used in our PHP extension test suite). That code implements the whole Blackfire’s protocol we are using to communicate with the browser extension and the agent. It also implements a compatibility layer for XHProf to let you benefit from the Blackfire’s infrastructure.
To make it work, you need to have XHProf installed (if not, just use Blackfire from day one!) oruprofiler, and add the
composer require blackfire/php-sdk ~1.0.
Unlike the Blackfire PHP extension, you need to manually instrument your code when using XHProf:
// get the probe main instance $probe = BlackfireProbe::getMainInstance(); // start the profiling $probe->enable(); // ... // stop the profiling and send the result to Blackfire $probe->close();
Profiling then needs to be enabled via the Companion (the Google Chrome extension) or via the
blackfire command line utility.
As a quick tip, remember that you can also easily upload any XHProf data file with
Using XHProf instead of the Blackfire’s PHP extension has some drawbacks though:
- I/O and CPU dimensions are not available;
- Garbage collector information is not supported;
- Times are not accurate;
- Anonymous function calls are not differentiated;
- Compatibility with newest version of PHP are far from perfect;
- Slower at many different levels (signatures for instance are only checked by the agent);
Why would you want to use XHProf then? Well, sometimes you need to improve the performance of an old application… one that currently uses PHP 5.2. Sounds familiar? The best advice is to upgrade your PHP version to a more recent one as you will benefit from free performance improvement. But it’s not always possible because of constraints outside of your control. But as Blackfire does not support PHP 5.2 (this PHP version is too outdated), using XHProf to instrument the code and Blackfire infrastructure for the report can be a great fallback.
Reading the source code of the Blackfire PHP SDK also tells you how Blackfire works behind the scene.
Happy XHProf profiling!