简体   繁体   English

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

[英]Xdebug PhpStorm: debugging scripts started with exec("php index.php")

I'm trying to add debugging to an old project that uses exec() to start a new session asynchronously from within another PHP script:我正在尝试将调试添加到使用exec()从另一个 PHP 脚本中异步启动新会话的旧项目中:

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

The normal PHP script is fully debugable with Xdebug but the script started with the exec command isn't because it can't map from file:///var/www/html/index.php to a local file location since it's started within CLI shell.普通的 PHP 脚本可以使用 Xdebug 完全调试,但使用 exec 命令启动的脚本不是因为它无法从file:///var/www/html/index.php到本地文件位置,因为它是在命令行界面。 The session started this way does trigger the debugger but can't find the file locally:以这种方式启动的会话确实触发了调试器,但在本地找不到该文件:

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.

I've followed the instructions to add the PHP_IDE_CONFIG to the env.我已按照说明将PHP_IDE_CONFIG添加到PHP_IDE_CONFIG中。 I've also added this to the server with 127.0.0.1 replaced with the desktop PC IP address (server is running in a docker container):我还将它添加到服务器中,将 127.0.0.1 替换为桌面 PC IP 地址(服务器在 docker 容器中运行):

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

Any pointers are greatly appreciated!任何指针都非常感谢!

UPDATE更新

Solution:解决方案:

Use the cli interpreter set to the docker container (in settings > Languages & Frameworks > PHP > CLI interpreter, add new, select docker and point it to the php binary) so that a debug session can be started with a new debugging configuration.使用设置为 docker 容器的 cli 解释器(在设置 > 语言和框架 > PHP > CLI 解释器中,添加新的,选择 docker 并将其指向 php 二进制文件),以便可以使用新的调试配置启动调试会话。 I've copied the arguments from the exec command into the new configuration and it can now fully debug the script.我已将 exec 命令中的参数复制到新配置中,现在它可以完全调试脚本。 I have to prepare a database table to make it fully testable but this is a working solution for me.我必须准备一个数据库表以使其完全可测试,但这对我来说是一个可行的解决方案。

Thanks for all the replies!感谢所有的答复!

You can solve the issue about the wrong php.ini file being loaded by specifying it in the command line:您可以通过在命令行中指定来解决加载错误的 php.ini 文件的问题:

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

Though I doubt that would make much of a difference as far as xdebug is concerned.虽然我怀疑就 xdebug 而言,这会产生很大的不同。

I think a better solution would be to just require the file, which would cause xdebug to not become lost when you fork a new process.我认为更好的解决方案是只require该文件,这会导致 xdebug 在您创建新进程时不会丢失。

require_once "/var/www/html/validata/index.php";

I've made a mistake how to refer to the server in PHP_IDE_CONFIG: export PHP_IDE_CONFIG="serverName=SomeName" should be run in the container where php runs, and SomeName should exactly match what is in PHPStorm/IntelliJ Settings > Languages & Frameworks > php > Servers > Name (not host).我在如何引用 PHP_IDE_CONFIG 中的服务器时犯了一个错误:export PHP_IDE_CONFIG="serverName=SomeName" 应该在运行 php 的容器中运行,而 SomeName 应该与 PHPStorm/IntelliJ Settings > Languages & Frameworks > 中的内容完全匹配php > 服务器 > 名称(不是主机)。 It's not a fqdn, just whatever is in the name field.它不是 fqdn,只是名称字段中的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM