How to setup Xdebug for profiling PHP applications

Xdebug offers a great insight into PHP application performance. It should only be run on a development environment though as it affects the performance of php applications. Profiling allows us to see how long each function takes, how many times functions were called, etc.

Lets get it setup.

  1. Use pecl to install the module:

    pecl install xdebug
  2. in php.ini add the following:

    xdebug.profiler_output_dir = "/tmp/" 
    xdebug.profiler_enable_trigger = 1
  3. Set a GET, POST or Cookie value to XDEBUG_PROFILE and the request will be profiled.

    For example, the simplest way to do this is to set a GET variable. Lets say you wanted to profile http://yourapplication/profile.php you would visit the following URL:


  4. The output/profile will be saved into /tmp. Download this to your PC and use a program such as QCacheGrind to open it.

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *