Loading xdebug via the -z argument

According to the PHP man page, the following command line options exist:

  --zend-extension file
   -z file        Load Zend extension file

      

Which supposedly means you can load xdebug as a zend extension that way, thus only loading Xdebug when you really need it, which is useful in my case as xdebug can seriously slow down the tests of the Drupal module, but I may need to debug some tests.

However, loading Xdebug this way doesn't work.

Environment: MacOS 10.10, PHP 5.6.3-dev, Xdebug 2.2.5.

$> ls -l /usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so
-rwxr-xr-x  1 root  wheel  319276 Oct 24 13:45 /usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so
$> grep xdebug /usr/local/etc/php/5.6/php.ini
zend_extension=/usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so
$> php -v |grep -i xdebug
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

      

So clearly, if specified in the file php.ini

, xdebug loads correctly. When I comment out the xdebug line,

> grep xdebug /usr/local/etc/php/5.6/php.ini
;zend_extension=/usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so

      

You can see that it is not loaded correctly:

> php -i|grep -i xdebug
>

      

However, when I try to use -z to load the extension,

> php -z /usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so -i|grep -i xdebug
> 

      

And no Xdebug functionality is included.

I haven't read anything that mentions that this doesn't work, but it doesn't. While it is not possible to load xdebug via -z, I do not completely rule out the possibility of writing a script to switch a line zend_extension

in the php.ini file, it is not very convenient.

Can someone explain why this is?

+3


source to share


1 answer


I have no explanation as to why it doesn't work with an argument -z

, but try:

php -dzend_extension=/usr/local/lib/php/extensions/debug-non-zts-20131226/xdebug.so -f myscript.php

      

Then you can create a script shortcut for the PHP scripts profile on the fly. Consider this bash script:



#!/bin/bash

php -dzend_extension=/path/to/xdebug.so -dxdebug.profiler_enable=1 -dxdebug.profiler_output_dir=$(pwd) $@

      

Then you can profile the script with ./xdebug -f script.php

, assuming xdebug

is the name of your script.

+1


source







All Articles