Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading xdebug via -z argument

According to the PHP manpage, the following command line options exist:

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

Which presumably means you can load xdebug as a zend extension this way, thereby only loading Xdebug when you actually need it, which in my case is helpful since xdebug can severely slow down Drupal unit tests, but I may need to debug some tests.

However, loading Xdebug this way does not seem to 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 when specified in the php.ini file, 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's correctly not loaded:

> php -i|grep -i xdebug
>

However, when I try using -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 enabled.

I haven't read anything that mentions that this doesn't work, but it doesn't. While failing to load xdebug via -z doesn't completely preclude me from writing a script to toggle the zend_extension line in the php.ini file, it's not exactly convenient.

Can anybody explain why this is?

like image 290
Bendoh Avatar asked Nov 11 '14 03:11

Bendoh


People also ask

How do I know if Xdebug is working?

Given that, you can confirm that xDebug is installed and in place by trying the following: 1) phpinfo() -- this will show you all the extensions that are loaded, including xDebug. If it is there, then it's a safe bet that it's working. 2) If that isn't good enough for you, you can try using the var_dump() function.

Why is Xdebug not working?

Xdebug cannot connect to PhpStorm This means that Xdebug tries to connect to the host and can't make the connection. To fix the issue, set xdebug. remote_connect_back=0 ( xdebug. discover_client_host=false for Xdebug 3) and make sure that xdebug.

Where do I put Xdebug in PHP ini?

For Windows, this is normally "c:\xampp\apache\bin\php. ini". Important note for Windows 7 & Vista users: As of August 2013 (XAMPP version 1.8. 2), the file "php_xdebug.


1 Answers

I have no explanation of why it does not work with the -z argument, but give this a try:

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

You can then create a shortcut script to profile PHP scripts 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) $@

You're then able to profile a script by using ./xdebug -f script.php, assuming xdebug is the name of your script.

like image 132
DavidS Avatar answered Sep 30 '22 04:09

DavidS