【问题标题】:Debug PHP processes started through `proc_open`调试通过 proc_open 启动的 PHP 进程
【发布时间】:2016-04-02 16:51:47
【问题描述】:

我正在尝试调试通过proc_open 启动的 PHP 进程。这意味着脚本代码本身作为字符串通过fwrite 传递。例如。通过使用 PHPUnit 调用如下:

$php = \PHPUnit_Util_PHP::factory();
$response = $php->runJob("<?php\nrequire 'some/framework/bootstrap.php';");

您可以在GitHub 上找到相关的源代码。作为调试器,我目前使用 Xdebug 和 IDE Eclipse。

我的 Xdebug 设置如下所示:

xdebug.remote_log=/tmp/xdebug.log
xdebug.idekey=ECLIPSE_DBGP
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_host=192.168.1.80

问题是这些进程没有达到断点。当我查看日志 (/tmp/xdebug.log) 时,我看到几个像这样的 init 数据包(在 fclose($pipes[0]); 之后正好三个):

<init xmlns="urn:debugger_protocol_v1"
      xmlns:xdebug="http://xdebug.org/dbgp/xdebug" 
      fileuri="dbgp://stdin" 
      language="PHP" 
      protocol_version="1.0" 
      appid="2091" 
      idekey="ECLIPSE_DBGP">
  <engine version="2.2.5"><![CDATA[Xdebug]]></engine>
  [...]
</init>

但是 Eclipse 从来没有像从 CLI (../vendor/phpunit/phpunit/phpunit -c [...]) 对父进程那样响应:

<init xmlns="urn:debugger_protocol_v1" 
      xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
      fileuri="file:///var/www/vendor/phpunit/phpunit/phpunit" 
      language="PHP" 
      protocol_version="1.0" 
      appid="2103" 
      idekey="ECLIPSE_DBGP">
   <engine version="2.2.5"><![CDATA[Xdebug]]></engine>
   [...]
</init>

所以这两个init 数据包之间的唯一区别是属性fileuri。对于通过proc_open 启动的进程,它只包含一个dbgp://stdin,这是有道理的,因为这些脚本来自一个字符串。

所以我的问题是如何让 eclipse 正确地用 fileuri="dbgp://stdin" 回复这些首字母?

似乎 Eclipse 仅在收到带有 fileuri 可以映射的 init 数据包时才响应。但是dbgp://stdin 的映射配置会是什么样子?

为了清楚起见,除了通过proc_open 启动的进程之外,我的设置完全正常且工作正常。这意味着我可以调试通过 CLI 或浏览器启动的脚本。

【问题讨论】:

    标签: php eclipse phpunit xdebug


    【解决方案1】:

    我也对此感兴趣。

    我使用 PHPStorm,IDE 会在您在 PHPUnit 中提到的位置停止调试。 PHPStorm 会抱怨它无法映射名为/&lt;path-to-file&gt;/- 的文件。我能够通过将调用中传递的 PHP 脚本字符串复制到 fwrite() 来使其工作,将其保存为本地某个文件,然后使用将路径 /&lt;path-to-file&gt;/- 映射到我在本地保存的文件。之后PHPStorm会通过它进行调试。

    我想类似的东西可以在 Eclipse 中工作。

    【讨论】:

    • 谢谢!我试试看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 1970-01-01
    • 2012-03-15
    • 2014-08-10
    相关资源
    最近更新 更多