Blackfire: A better Experience for XHProf Users

By Fabien Potencier, on Apr 14, 2015

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 blackfire/php-sdk dependency: composer require blackfire/php-sdk ~1.0.

Unlike the Blackfire PHP extension, you need to manually instrument your code when using XHProf:

Profiling then needs to be enabled via the Companion (the Google Chrome extension) or via theblackfire command line utility.

As a quick tip, remember that you can also easily upload any XHProf data file with blackfire upload.

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!

Fabien Potencier

Fabien Potencier is the CEO and founder of Blackfire.io. He founded the Symfony project in 2004 as he constantly looked for better ways to build websites. Fabien is also the creator of several other Open-Source projects, a writer, a blogger, a speaker at international conferences, and the happy father of two wonderful kids.