是否可以使用 xdebug 调试 exec() 和 system() 调用?

Is it possible to debug exec() and system() calls with xdebug?

我正在开发一个遗留应用程序,它非常大量使用system()exec()到运行php 脚本。一旦执行 system() 调用,Xdebug 会话 variables/headers 似乎不会跟进。

是否有可能以某种方式强制PHP始终识别下游连接?

例如,index.php 包含一行:

exec('php some_script.php')

如果我从 browser/cli 运行 index.php 可以在 some_script.php 中放置一个断点并使用调试器注册断点吗?

这是我的 xdebug.ini:

xdebug.remote_enable=1
xdebug.remote_host=10.0.2.2
xdebug.remote_port=9000
xdebug.connect_back = 1
xdebug.idekey = PHPSTORM
xdebug.remote_handler = dbgp
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_log = /var/log/xdebug.log

是的,这是可能的。您只需要在 exec("php .

之后传递一些 xdebug 选项

就我而言,现在是:

if (extension_loaded('xdebug')) {
    $options = [
        '-d xdebug.mode=debug',
        '-d xdebug.client_host=host.docker.internal'
    ];
}
$serializedOptions = implode(' ', $options);
exec("php $serializedOptions $cliPath $input", $output);

你可能需要通过 xdebug zend_extension,我不得不在另一个项目中完成,例如:

-d zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so