Performance profiling php in my opinion is best done with xdebug and kcachegrind (install it via APT on an Ubuntu virtual machine and save yourself some trouble. I know you can get it to work with xwindows natively on a mac but damn it’s not easy and it certainly isn’t as pretty as using it in KDE 4 )

How to performance profile an app is an art not covered here. Seriously if you want to start somewhere I suggest reading this article over at Zend developer zone (It’s from 2007 but it’s still relevant):

http://devzone.zend.com/article/2899-Profiling-PHP-Applications-With-xdebug

Also there is a great article if you can find it from the September 2004 edition of php|Architect… If you can’t find it on the internet email me and I will send you a PDF version of it. It is a complete and comprehensive article and should not be missed if you are working with xdebug at all.

So finally back on topic:

Installing xdebug is pretty easy assuming you have php/pecl/pear installed… If you don’t I suggest you use yum and if you don’t have that installed then just follow this tutorial: http://www.matteomattei.com/en/install-yum-and-php-pear-on-centos-5

Anyway once you have pecl installed you can run the following:

# pear install pecl/xdebug

downloading xdebug-2.0.5.tgz …
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
……………………………………………………done: 289,234 bytes
67 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
/usr/bin/phpize: /tmp/tmpOcEvNL/xdebug-2.0.5/build/shtool: /bin/sh: bad interpreter: Permission denied
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.

Woops!

Looks like something is up with running /tmp/tmpOcEvNL/xdebug-2.0.5/build/shtool

I have seen this type of build error before when using other package management systems and it turns out that what I thought was true. That the /tmp directory was mounted with the noexec switch.

See here:

# mount -l | grep /tmp
simfs on /tmp type simfs (rw,noexec)
simfs on /var/tmp type simfs (rw,noexec)

# pear install pecl/xdebug
downloading xdebug-2.0.5.tgz …
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
……………………………………………………done: 289,234 bytes
67 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
/usr/bin/phpize: /tmp/tmpOcEvNL/xdebug-2.0.5/build/shtool: /bin/sh: bad interpreter: Permission denied
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.

So let’s remount it with the exec switch:

mount -o remount,exec /tmp

And now let’s see what mount -l says:

mount -l | grep /tmp
simfs on /tmp type simfs (rw)
simfs on /var/tmp type simfs (rw,noexec)

So we can see that now the /tmp does not have noexec listed.

Ok let’s try and install via pecl again:

# pear install pecl/xdebug
downloading xdebug-2.0.5.tgz …
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
……………………………………………………done: 289,234 bytes
67 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
building in /var/tmp/pear-build-root/xdebug-2.0.5
running: /tmp/tmp3tHVR2/xdebug-2.0.5/configure
checking for egrep… grep -E
checking for a sed that does not truncate output… /bin/sed
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… configure: error: cannot run C compiled programs.
If you meant to cross compile, use `–host’.
See `config.log’ for more details.
ERROR: `/tmp/tmp3tHVR2/xdebug-2.0.5/configure’ failed

Well were not in the clear yet the error looks surprisingly similar… let’s just try to mount /var/tmp without the noexec switch as well:

# mount -o remount,exec /var/tmp

And again the pecl install:

# pear install pecl/xdebug
downloading xdebug-2.0.5.tgz …
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
…………………………………………..done: 289,234 bytes
67 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
building in /var/tmp/pear-build-root/xdebug-2.0.5
running: /tmp/tmpkWolpH/xdebug-2.0.5/configure
checking for egrep… grep -E
checking for a sed that does not truncate output… /bin/sed
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…

<SNIP>

Build process completed successfully
Installing ‘/var/tmp/pear-build-root/install-xdebug-2.0.5//usr/lib64/php/modules/xdebug.so’
install ok: channel://pecl.php.net/xdebug-2.0.5
You should add “extension=xdebug.so” to php.ini

Nice. Ok so now it worked. Notice the path that it was installed to (on this 64 bit machine it was): /usr/lib64/php/modules/xdebug.so
We will need that later when we put it in our new /etc/php.d/xdebug.ini: (the contents of which I will explain in another blog post but for now the comments inside of it should be self explanatory)

#extension_dir = “/usr/local/lib/php/20060613″

#doc_root=”/usr/local/apache2/htdocs/web”

#the following was added by jesse to fix the path variables when run in cgi mode
#cgi.fix_pathinfo=0

zend_extension=”/usr/local/lib/php/20060613/xdebug.so”
#xdebug.remote_enable=1

;JESSE: the following was taken from: http://code.google.com/p/syslogr-utils/wiki/XdebugHelper
;When using Eclipse with PDT and xdebug — make sure to change your
;tools –> addons –> xdebug helper –> preferences –> idekey = ECLIPSE_DBGP
;(This is the setting that XDEBUG_SESSION_START is set to on your web browser URL)

;JESSE: I have put the following notes in from some research into profiling with webgrind:
;(they were taken from: http://www.chrisabernethy.com/php-profiling-xdebug-webgrind/ )

;NOTE: usually use cachegrind.out.%t.%p when I want one output file per script run,
;but if I want to run a script multiple times and see the aggregate numbers
;I use cachegrind.out.%s and set xdebug.profiler_append = on

;NOTE: A Nice to know, for different cachegrind files per host you can use %H in the
;profiler_output_name, according to
;http://www.xdebug.org/docs/all_settings#trace_output_name

;Always profile scripts with xdebug:
;xdebug.profiler_enable = 1

#xdebug.profiler_enable=1

;Alternatively, enable profiling with GET/POST parameter XDEBUG_PROFILE,
;e.g. http://localhost/samplepage.php?XDEBUG_PROFILE:
;xdebug.profiler_enable_trigger = 1

xdebug.profiler_enable_trigger=1

xdebug.profiler_output_dir=”/tmp/xdebug/”

;the following forces xdebug to append to the outfile rather than
;overwrite it on each exec of a script
;xdebug.profiler_append=On

;the patterns for the names of the outfiles
;xdebug.profiler_output_name = cachegrind.out.%s
xdebug.profiler_output_name = cachegrind.out.%t.%p

;the following opens debug output links in textmate
xdebug.file_link_format = “txmt://open?url=file://%f&line=%l”

xdebug.remote_host=”127.0.0.1″
xdebug.remote_port=9000
xdebug.remote_handler=”dbgp”
xdebug.remote_mode=req
xdebug.idekey=1

Now check the php-cli and see if xdebug shows up in it’s ini dump.

php -i | grep xdebug
/etc/php.d/xdebug.ini,
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value

<snip>

Looking good!

Oh and obviously restart apache… /etc/init.d/httpd restart

Sweet.

Installing xdebug on centos 5

One Response to “Installing xdebug on centos 5”

  1. Hello,

    Thanks for this post, very useful.

    BTW, I humbly suggest that you use a bigger font, it’s not pretty readable now.

    [WORDPRESS HASHCASH] The poster sent us ‘52288192 which is not a hashcash value.

Add Your Comment

Powered by WP Hashcash