Setting Up and Configuring Xdebug

Setting up and Configuring Xdebug

Install Xdebug
There are three ways you can install Xdebug.

- Installing precompiled modules.
- Install through PEAR/PECL.
- Compiling from source.

Visit http://xdebug.org/docs/install for detailed instructions.


Configure PHP to Use Xdebug
Modify php.ini

Once Xdebug was installed, add the following line to php.ini.
zend_extension=/PATH_TO/xdebug.so

Note: Optionally, you may create a dedicated file (xdebug.ini) for Xdebug settings.

Reload httpd

Reload webserver first for settings to take effect.
/etc/init.d/httpd reload

Configure Profiler and Tracer
I. Profiler

Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file.

There are two options in profiling, Automated or Selective.

Automated - Profiler files are generated for each request.

Selective - Profiler files are generated only when XDEBUG_PROFILE GET/POST parameter was used or cookie with the name XDEBUG_PROFILE was sent.

For Automated Profiling, add the following line to php.ini
xdebug.profiler_enable = 1

Once you visit your site (e.g. http://example.com/), this line will:
- Enable automated profiling for each request.
- Write profiler data to /tmp.
- Dump traces into a file named cachegrind.out.%p (%p = process id) e.g. cachegrind.out.6158. Visit http://xdebug.org/docs/all_settings#trace_output_name for more format specifiers.

Reload webserver first for settings to take effect.
/etc/init.d/httpd reload

Note: If you didn't indicate xdebug.profiler_enable_trigger, xdebug.profiler_output_dir, xdebug.profiler_output_name; their default values will be used instead which are 0, /tmp, cachegrind.out.%p respectively.

For Selective Profiling, use the following line
xdebug.profiler_enable_trigger = 1

Once you visit your site (e.g. http://example.com/) and used XDEBUG_PROFILE GET/POST parameter or send cookie named XDEBUG_PROFILE, this line will:
- Enable selective profiling of requests.
- Write profiler data to /tmp.
- Dump traces into a file named cachegrind.out.%p (%p = process id) e.g. cachegrind.out.6158. Visit http://xdebug.org/docs/all_settings#trace_output_name for more format specifiers.

Reload webserver first for settings to take effect.
/etc/init.d/httpd reload

Note:

1. In order to prevent the profiler to generate profile files for each request, you need to set xdebug.profile_enable to 0.

2. If you didn't indicate xdebug.profiler_output_dir, xdebug.profiler_output_name; their default values will be used instead which are /tmp, cachegrind.out.%p respectively.

II. Tracer

Those so-called "function traces" can be a help for when you are new to an application or when you are trying to figure out what exactly is going on when your application is running. The function traces can optionally also show the values of variables passed to the functions and methods, and also return values. In the default traces those two elements are not available.

Add the following line to php.ini
xdebug.auto_trace = 1

Once you visit your site (e.g. http://example.com), this line will:
- Enable automated tracing of function calls.
- Write traces data to /tmp.
- Dump traces into a file named trace.%c (%c = crc32 of the current working directory) e.g. trace.1258863198.xt. Visit http://xdebug.org/docs/all_settings#trace_output_name for more format specifiers.

Reload webserver first for settings to take effect.
/etc/init.d/httpd reload

Note: If you didn't indicate xdebug.trace_output_dir, xdebug.trace_output_name; their default values will be used instead which are /tmp, trace.%c respectively.

References

Xdebug: Documentation, http://xdebug.org/docs/

Comments

Popular posts from this blog

Remote Deployment with Ant and Rsync

Site Performance Enhancement