PhpStorm中的XDebug会话停留在curl_exec调用上

Sol*_*ear 5 php xdebug phpstorm

我有以下简化的API:

http://localhost/app/apiA
http://localhost/app/apiB
Run Code Online (Sandbox Code Playgroud)

在哪里apiA处理,然后执行这些简单的操作,以便apiA调用apiB:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, site_url('apiB'));
//various other options
$response = curl_exec($curl);
Run Code Online (Sandbox Code Playgroud)

现在我在PhpStorm中的一个断点正好在curl_exec调用中apiA,另一个在该apiB方法的第一行右侧.会发生什么事情,首先,XDebug停留在curl_exec通话中并将无限期地留在那里; 但是,如果我按下Break,停止翻译,XDebug会中断,但会激活我的断点apiB!

我希望它执行调用curl_exec并点击断点apiB,然后在完成后返回第一个断点.有没有办法配置XDebug和/或PhpStorm来做到这一点?

Sol*_*ear 15

这在PhpStorm中非常简单,只需转到Settings - > PHP - > Debug,在External Connections部分中将Max并发连接的值增加到你需要的数字 - 在我的情况下,2就足够了.

设置截图


小智 6

我终于让它可靠地工作了.所以我会修改我的答案.我意识到我的答案与我在其他地方看到的答案基本相同,但不知怎的,我不理解它们,所以我会尽力使它更清楚.

这是在phpstorm 9.5和10上测试的,但很可能在早期版本上也是如此.我使用Linux,(Kubuntu 14.04).(假设xdebug已经在phpstorm中正常工作.)

设置是我在命令行上从curl启动会话,然后请求由我的应用程序中的路由(routeA)处理,该路由使用cURL(即curl_exec())向另一个路由(routeB)发送新请求.然后将结果返回到routeA,最后返回到命令行.

问题:在整个请求/响应周期中在phpstorm/xdebug中进行完全调试.

为了使其工作,需要在xdebug中进行以下设置.必须设置xdebug来处理远程调试会话,并且必须有一个可用于触发调试会话的idekey - 我没有找到其他似乎相关的设置.更改后重新启动服务器.

xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
Run Code Online (Sandbox Code Playgroud)

其次,在phpstorm中,您需要允许多个外部同时连接.我认为cURL调用(从一个路由到另一个路由)被视为外部,在第一个连接等待第二个返回时保持活动的意义上,如果链更长,则至少需要2个可能更多.此设置可在设置中找到

Language & Frameworks > php > Debug > External Connections
Run Code Online (Sandbox Code Playgroud)

最后你需要告诉phpstorm听.你可以在几个地方找到这个选项,一个地方在运行菜单中(在版本10中它是朝向底部)

Run > Start Listening for PHP Debug Connections
Run Code Online (Sandbox Code Playgroud)

然后在命令行中,您将使用PHPSTORM ide键来触发调试:

curl -i -v http://yoursite/routea/?XDEBUG_SESSION_START=PHPSTORM
Run Code Online (Sandbox Code Playgroud)

在routeA中,您可以像这样创建cURL调用

public function routeaAction()
{
    ...

    //initialize the curl object
    $curl = curl_init("http://yoursite/routeb/");
    // trigger the second debug connection by setting a special cookie
    curl_setopt($curl, CURLOPT_COOKIE,"XDEBUG_SESSION=PHPSTORM");

    // debugging options
    // short timeout, stop on errors, show headers, be verbose etc.
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_FAILONERROR,true);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLINFO_HEADER_OUT,true);
    curl_setopt($curl, CURLOPT_TIMEOUT,2);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);

    // follow along to the second route and the return the result
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    // if your site is a virtual host - typical on your local dev machine
    // you need to tell your web server which site (virtual host) you want
    // the url is not enough - you need to set the Host header
    // there may be other headers you want to set - do it like this
    $requestHeaders[] = "Host: yoursite";
    $requestHeaders[] = "Cache-Control: no-cache";
    $requestHeaders[] = "Pragma: no-cache";
    curl_setopt($curl, CURLOPT_HTTPHEADER,$requestHeaders);

    // finally you're ready to send the request
    $data = curl_exec($curl);
    $errno = curl_errno($curl)
    if ($errno){
        $data .= 'Error: ' . curl_error($curl) ."\n";
    }
    curl_close($curl);

    return $data;
}
Run Code Online (Sandbox Code Playgroud)

我会留下链接,因为它们很有帮助,但删除了我的引用,因为它们不是必需的.

这个给出了如何为cURL设置选项的一个很好的例子:

/sf/users/266952381/

此链接解释了Windows下的一些xdebug.ini设置

在NetBeans上使用XDebug进行卷曲

[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug-2.2.5-5.4-vc9.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0 
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_autostart = 1
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port = "9000"
xdebug.trace_output_dir = "C:\xampp\tmp"
xdebug.max_nesting_level = 200
xdebug.idekey = "netbeans-xdebug"
Run Code Online (Sandbox Code Playgroud)

此链接有一些特定于netbeans的信息,但也可能适用于phpstorm

根据外部请求在Netbeans中启动XDebug

转到项目属性>运行配置>高级>调试URL并检查不要打开Web浏览器(*).不要在调试器代理下设置主机.保存这些设置.在项目窗口中,在项目上:右键单击> debug(这将开始侦听调试连接).没有浏览器启动.在浏览器中输入http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug.它应该打破netbeans.至少这是发生在这里:)

在HTTP GET请求上有效URL的404状态的FileNotFoundException

在curl中找不到404