Xdebug PhpStorm:以exec(“ php index.php”)开始的调试脚本

问题描述 投票:0回答:1

我正在尝试将调试添加到使用exec()从另一个PHP脚本中异步启动新会话的旧项目中:

exec("php /var/www/html/validata/index.php",$result) 

普通的PHP脚本可以用Xdebug完全调试,但是用exec命令启动的脚本不是因为它不能从file:///var/www/html/index.php映射到本地文件位置,因为它是在CLI Shell中启动的。以这种方式启动的会话会触发调试器,但无法在本地找到文件:

Cannot find file '/var/www/html/validata/index.php' locally.
To fix it set server name by environment variable PHP_IDE_CONFIG and restart debug session.

我已按照说明将PHP_IDE_CONFIG添加到环境中。我还将其添加到服务器,其中127.0.0.1替换为台式机IP地址(服务器在docker容器中运行):

export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

非常感谢任何指针!

php docker phpstorm xdebug
1个回答
0
投票

您可以通过在命令行中指定它来解决有关加载错误的php.ini文件的问题:

exec("php -c " . escapeshellarg(php_ini_loaded_file()) .
    " /var/www/html/validata/index.php",$result);

尽管我怀疑,就xdebug而言,这会有很大的不同。

我认为一个更好的解决方案是仅require该文件,当您分叉一个新进程时,这将导致xdebug不会丢失。

require_once "/var/www/html/validata/index.php";
© www.soinside.com 2019 - 2024. All rights reserved.