XHProf bundle for Symfony 2
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 30 commits ahead, 133 commits behind jonaswouters:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



What is XHProf?

XHProf is a hierarchical profiler for PHP. It reports function-level call counts and inclusive and exclusive metrics such as wall (elapsed) time, CPU time and memory usage. A function's profile can be broken down by callers or callees. The raw data collection component is implemented in C as a PHP Zend extension called xhprof. XHProf has a simple HTML based user interface (written in PHP). The browser based UI for viewing profiler results makes it easy to view results or to share results with peers. A callgraph image view is also supported.

See official documentation

What does this Symfony 2 Bundle do?

This bundle helps you to easily use the XHProf bundle with the web debug toolbar in Symfony 2.


Make sure you have XHProf installed. If you are on a mac you can easily install it via Macports sudo port install php5-xhprof

Get the bundle

To install the bundle, place it in the src/Jns/Bundle directory of your project (so that it lives at src/Jns/Bundle/XhprofBundle). You can do this by adding the bundle as a submodule, cloning it, or simply downloading the source.

git submodule add https://github.com/jonaswouters/XhprofBundle.git src/Jns/Bundle/XhprofBundle

Add the Jns namespace to your autoloader

If this is the first Jns bundle in your Symfony 2 project, you'll need to add the Jns namespace to your autoloader. This file is usually located at app/autoload.php.

    'Jns'                       => __DIR__.'/../src'
    // ...

Initializing the bundle

To initialize the bundle, you'll need to add it in your kernel. This file is usually located at app/AppKernel.php. Loading it only in your dev environment is recommended.

public function registerBundles()
    // ...

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        // ...
        $bundles[] = new Jns\Bundle\XhprofBundle\JnsXhprofBundle();

Configure the XHProf locations.

The Bundle comes preconfigured for the macports php5-xhprof default installation, with the xhprof web located at http://xhprof.localhost. To change these settings for your environment you can override the defaults by defining the following settings in your config. The config is usually located at app/config/config.yml.

    location_lib:   /opt/local/www/php5-xhprof/xhprof_lib/utils/xhprof_lib.php
    location_runs:  /opt/local/www/php5-xhprof/xhprof_lib/utils/xhprof_runs.php
    location_web:   http://xhprof.localhost

Enable XHProf via web

To be able to enable XHProf via web you need to have APC installed. Then you can add the following to your routing configuration.

_xhprof: resource: "@JnsXhprofBundle/Resources/config/routing.yml"

Then you can call the following URL:


That URL accepts two parameters:

  • enable: Whether to enable or disable XPhrof. The values could be 0 for disabled and 1 for enabled.
  • ttl: Time To Live. A value in seconds specifying for how long XHProf should be enabled.


  • Add way to choose which XHProf helper to use (to not enable only via APC).
  • Implement a helper that has the old behavior (Always enables XHProf).
  • Implement helper function to return profile type string. (As of now it uses the route name).
  • Implement profile location parameter. (Now uses /tmp by default).