Installing XDebug and configuring for PHP profiling purposes.

Xdebug and Php Profiling

Segment 1.

Installing and Configuring XDebug

 In this brief article I will instruct to you how to install and quickly configure Xdebug for PHP5. This article was built in relation to my Xdebug series of articles that helps you profile PHP quickly and with relative ease to find out why PHP is using excessive Memory, or just running very sluggishly.

Installation of XDebug Package

I have found that the easiest ways to install Xdebug are from the OS packages or the pecl manager.
 Official URL:
Choose the appropriate install for you: 
Centos/Redhat: yum install xdebug
Ubuntu/Debian: apt-get xdebug
 Pecl: pecl install xdebug


After we installed the Xdebug package you need to locate library. I suggest using the locate command if you have it installed otherwise find works.
Locate Command: updatedb && locate
Find Command: find / -name ‘’ 2> /dev/null

Php ini Config XDebug.ini  file:
I have put together a pretty basic Xdebug config file, I like to keep it seperate from the primary php.ini file myself. 
Paste the entries below in a ini file /etc/php5/conf.d folder or whatever the Php folder is for Ubuntu. For example I use /etc/php5/conf.d/xdebug.ini.

xdebug.trace_output_name= cachegrind.out.%s.%t.trace.%p
xdebug.profiler_output_name =cachegrind.out.%s.%t.profile.%p

***Note: while Profile enabler are enabled, Xdebug will keep parsing all your php requests and your log folder will/can grow very large quickly. 

Setting the permissions and ownerships

I have manually create a log folder to keep track of the traces made by Xdebug. We then of course need to set the apache group ownership and writability, so that apache can create our traces. Finally restart Apache
mkdir /var/log/php
chown root:apache /var/log/php
chmod 775 /var/log/php
Centos/Redhat: service httpd restart
Ubuntu/Debian: service apache2 restart


Lets test this out really quickly shall we? There is a script that comes installed with xdebug that will analyze your last running php process’s to see what was used. This little nugget is perfect to test with. 
 Here is a better understanding of what the tracefile-analyser.php is and does view: .

First we find the file:

Locate Command: locate tracefile-analyser.php
Find Command: find / -name ‘tracefile-analyser.php‘ 2> /dev/null

I just copy this to the document root directory of where you will be testing the script from. 

Next we will generate a Trace log file by creating a quick php script test.php script. Use my short script below.  You just need to browse to the url,  which will create a new log file in /var/log/php.  Browse
echo “Hello World”.”n”;
echo “<br>”;
echo “<br>”;
echo “<br>”;
echo date( ‘m/d/y h:ia’ );
echo “<br>”;
echo “<br>”;
$var = ‘122.34343The’;
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343

Alright now goto /var/log/php and find your new log file that might end in .xt and use the command below:
php /path/to/your/tracefile-analyser.php cachegrind.out.xxxxx.xt memory-own 20

If you get something that looks like this below, your xdebug is working!
Showing the 20 most costly calls sorted by ‘memory-own’.

                Inclusive        Own
function#calls  time     memory  time     memory
{main}       1  0.0026     1144  0.0001      784
date         1  0.0025      360  0.0025      360
floatval     1  0.0000        0  0.0000        0

jim has written 83 articles

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>