Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49214

PHP profiling with XHprof

$
0
0

If you're looking to track down the module which is killing your page load times, you may need profiling. Most people have used xdebug for this in the past with something like webgrind to display the information. Things have gotten easier.

Facebook has developed a PHP extension called XHprof and released it under the Apache license. It comes with a nice sample web interface.

While this article formerly described the use of a module specifically for xhprof, the devs of the devel module have integrated XHprof into both the versions for Drupal 6.x and 7.x and there's no longer any need to use a separate module.

The XHprof extension is available through PECL, but I made an Ubuntu package for ease of installation. So for those Ubuntu users, add my repo with

add-apt-repository ppa:brianmercer/php5-xhprof
aptitude update
aptitude install php5-xhprof graphviz

The graphviz package is required to generate the "callgraphs". Restart your php-fpm or apache or whatever you use for php.

Enable the devel module and enter the following values:

XHprof directory:  /usr/share/php5-xhprof/

XHProf URL: /xhprof_html

and for nginx place the following locations at the top of your server config:
location ^~ /xhprof_html/ {
    root /usr/share/php5-xhprof/;
    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/php5-xhprof$fastcgi_script_name;
    fastcgi_pass php;

    location ~ ^.*.(css|js|gif)$ {}
  }

By default, XHprof is configured to place the dump files in /tmp. Feel free to delete them after you're done. To disable XHprof you can remove the package through apt or just comment out the lines in /etc/php5/conf.d/xhprof.ini with semicolons and restart php.


Viewing all articles
Browse latest Browse all 49214

Trending Articles