我终于让它可靠地工作了。所以我会修改我的答案。我意识到我的答案与我在其他地方看到的基本相同,但不知何故我没有理解它们,所以我会尽量让它更清楚。
这在 phpstorm 9.5 和 10 上进行了测试,但很可能在早期版本上工作相同。我使用 Linux,(Kubuntu 14.04)。 (假设 xdebug 已经在 phpstorm 中正常工作了。)
设置是我在命令行上从 curl 发起会话,然后请求由我的应用程序中的路由 (routeA) 处理,该路由使用 cURL 向另一个路由 (routeB) 发送新请求(即 curl_exec( ))。然后将结果返回给routeA,最后返回命令行。
问题:通过请求/响应周期在 phpstorm/xdebug 中进行全面调试。
为了使它工作,需要在 xdebug 中进行以下设置。 xdebug 必须设置为处理远程调试会话,并且必须有一个可用于触发调试会话的 idekey - 我没有找到其他似乎相关的设置。更改后重新启动服务器。
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
其次,在phpstorm中,你需要允许多个外部同时连接。我相信 cURL 调用(从一个路由到另一个路由)被视为外部的,因为第一个连接在等待第二个返回时保持活动状态,如果链更长,至少需要 2 个。这个设置可以在设置中找到
Language & Frameworks > php > Debug > External Connections
最后你需要告诉 phpstorm 去听。你可以在几个地方找到这个选项,一个地方在运行菜单中(在版本 10 中它在底部)
Run > Start Listening for PHP Debug Connections
然后在命令行你将使用 PHPSTORM ide 键来触发调试:
curl -i -v http://yoursite/routea/?XDEBUG_SESSION_START=PHPSTORM
在 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;
}
我会留下链接,因为它们很有帮助,但我会从中删除我的引号,因为它们不是必需的。
这是一个很好的例子来说明如何为 cURL 设置选项:
https://stackoverflow.com/users/3813605/misunderstood
这个链接解释了windows下的一些xdebug.ini设置
Curl with XDebug on NetBeans
[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"
此链接包含一些特定于 netbeans 的信息,但也可能适用于 phpstorm
Launch XDebug in Netbeans on an external request
转到项目属性 > 运行配置 > 高级 > 调试 url 并检查不要打开 Web 浏览器 (*)。不要在调试器代理下设置主机。保存这些设置。在项目窗口中,在您的项目上:鼠标右键单击 > 调试(这将开始侦听调试连接)。没有启动浏览器。在浏览器中输入http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug。它应该在netbeans中中断。至少这就是这里发生的事情:)
FileNotFoundException with 404 status for valid URL on HTTP GET request
404 not found in curl