调用exec时,PHP调试器挂起('php ...')

时间:2014-12-17 11:17:16

标签: php debugging netbeans xdebug

我有一个PHP脚本,在某一点上,我在另一个PHP脚本上调用exec()。这非常正常,但在NetBeans中使用XDebug调试器时会挂起。这导致了各种各样的问题,因为我无法调试整个应用程序。

这是一个简单的例子:

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;
?>

如果我运行 test1.php,它将运行完成并产生预期的输出。

如果我 debug test1.php,它会挂在exec(&#39; php ...&#39;)行上。

我已经尝试过使用shell_exec,并遇到同样的问题。我也尝试过执行.sh文件或其他可执行文件,没有任何问题。

起初我认为xdebug以某种方式附加到exec启动的新PHP进程并将其锁定,但是我已经检查了我的php.ini并且xdebug.remote_autostart=off

我知道通过exec()调用PHP脚本是一种奇怪的处理方式;它实际上是一个外部提供的PHAR文件,我们在实际的代码库中执行,但上面的小例子有相同的症状,所以我假设它是同样的问题。

如果它是相关的,我使用PHP 5.5.13,Xdebug 2.2.3,Netbeans 7.3.1,Ubuntu 12.0.4。

1 个答案:

答案 0 :(得分:3)

发生这种情况是因为当你执行第二个脚本时,xdebug已经忙,所以内存脚本停顿,外部脚本的执行无法继续。

要解决这个问题:

  1. 注释掉php ini中的xdebug设置并检查环境变量XDEBUG_CONFIG是否包含任何
  2. 使用xdebug参数启动主脚本(php -dxdebug.remote_enable = 1 -dxdebug.remote_mode = req -dxdebug.remote_port = 9000 -dxdebug.remote_host = 127.0.0.1)
  3. exec第二个脚本没有xdebug参数:exec(&#39; php script.php&#39;)
  4. 要调试内部脚本,请在没有xdebug的情况下启动第一个脚本,使用xdebug启动exec,反之亦然。