I have a PHP script in which, at one point, I call exec() on another PHP script. This runs perfectly fine, but it hangs when using the XDebug debugger in NetBeans. This is causing me all sorts of problems, as I'm unable to debug the entire application.
Here is a trivial example:
test1.php
<?php
$output = array();
$status = 0;
exec('echo "Running inside test 1"', $output, $status);
exec('php ' . __DIR__ . '/test2.php', $output, $status); // Debugger hangs here
var_dump($output);
var_dump($status);
?>
test2.php
<?php
echo "Running inside test 2" . PHP_EOL;
?>
If I run test1.php, it runs to completion and produces the expected output.
If I debug test1.php, it hangs on the exec('php ...') line.
I've tried this with shell_exec, and get the same problem. I've also tried exec'ing on a .sh file or other executable, with no issues.
At first I thought that xdebug was somehow attaching to the new PHP process started by the exec and locking it, but I've checked my php.ini and have xdebug.remote_autostart=off
.
I'm aware that calling a PHP script via exec() is a strange way of doing things; it is actually an externally provided PHAR file which we are exec'ing in the real codebase, but the trivial example above has the same symptom, so I'm assuming it is the same problem.
In case it is relevant, I'm using PHP 5.5.13, Xdebug 2.2.3, Netbeans 7.3.1, Ubuntu 12.0.4.
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.
Verify that Xdebug is properly running by checking again with phpinfo() or php -v as explained above. Note that 9003 is the default port. If this port is used by another service on your system, change it to an unused port. After adding these settings, restart your webserver again.
This happens because when you exec second script, xdebug is already busy, so innder script stalls, and execution of outer script cannot be continued.
To deal with this problem:
To debug inner script, start first script without xdebug, and exec with xdebug, vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With