简体   繁体   English

并行调试-xdebug和phpstorm

[英]Parallel debugging - xdebug and phpstorm

I try to do parallel debugging. 我尝试进行并行调试。 I use PhpStorm debugging tutorial (about 30 minute and more) with frontend.php and backend.php files: 我将PhpStorm调试教程 (约30分钟以上)与frontend.php和backend.php文件一起使用:

frontend.php file: frontend.php文件:

<?php

$personJson = file_get_contents('http://localhost:777/projects/debug-both/backend.php/backend.php');
$person = json_decode($personJson);

var_dump($person);

backend.php file: backend.php文件:

<?php

class Person {
    public $name;
    public $email;
}

$person = new Person();

$person->name = 'Something';
$person->email = 'something@something.com';

echo json_encode($person);

I use zero configuration method. 我使用零配置方法。 When I launch frontend file in browser with debug session, in PhpStorm debugging session is being start but I cannot step over in line: 当我在带有调试会话的浏览器中启动前端文件时,在PhpStorm中调试会话正在启动,但是我无法跨过行:

file_get_contents('http://localhost:777/projects/debug-both/backend.php/backend.php');

to go to the backend.php file as in tutorial (31:36 in the video). 转到教程中的backend.php文件(视频中的31:36)。

Question: how to make it working? 问题:如何使其工作? In this video there is nothing more and it seems it should work right away but it doesn't. 在此视频中,仅此而已,似乎应该可以立即使用,但事实并非如此。

I include my xdebug configuration from phpinfo 我包括来自phpinfo的xdebug配置 来自phpinfo的xdebug配置 and xdebug configuration in PhpStorm 和xdebug配置在PhpStorm中 PhpStorm中的xdebug配置

1. Settings | PHP | Debug | Max simultaneous connections 1. Settings | PHP | Debug | Max simultaneous connections Settings | PHP | Debug | Max simultaneous connections Settings | PHP | Debug | Max simultaneous connections -- should be more than 1. You already have it set. Settings | PHP | Debug | Max simultaneous connections -应该大于1。您已经设置了它。

2. xdebug.remote_autostart should be 1 / on . 2. xdebug.remote_autostart应该为1 / on This will tell xdebug to attempt to debug every single request regardless of debug cookie/parameter. 这将告诉xdebug尝试调试每个单个请求,而不管调试cookie /参数如何。

This is needed as your 2nd script will not receive the same cookies/parameters as original script (as it is technically separate request). 这是必需的,因为您的第二个脚本将不会收到与原始脚本相同的cookie /参数(因为这在技术上是单独的请求)。

Yes, this option may not convenient for day-to-day development as it will attempt to debug every single request, and if debug client is not available ... you will see around 1 sec delay in script execution. 是的,此选项可能不适用于日常开发,因为它将尝试调试每个单个请求,并且如果调试客户端不可用...您将看到脚本执行大约延迟1秒。

The alternative approach (in your specific case) would be adding xdebug GET parameter (eg ?XDEBUG_SESSION_START=1 ) into URL when calling for 2nd script. 替代方法 (在您的特定情况下)将是在调用第二个脚本时将xdebug GET参数(例如?XDEBUG_SESSION_START=1 )添加到URL中。 This will tell xdebug to debug this request. 这将告诉xdebug调试此请求。 For example: 例如:

file_get_contents('http://localhost:777/projects/debug-both/backend.php/backend.php?XDEBUG_SESSION_START=1');

As you can see this approach requires modifying your code (requested URLs). 如您所见,这种方法需要修改代码(请求的URL)。 Quite often this is not desired. 通常这是不希望的。

Yet another alternative is to set breakpoint programmatically by adding xdebug_break(); 另一种选择是通过添加xdebug_break();来以编程方式设置断点xdebug_break(); . This should trigger debugger even without those extra params/cookies or remote_autostart setting. 即使没有这些额外的参数/ cookie或remote_autostart设置,这也应该触发调试器。

The downside is the same: code manipulation is required. 缺点是一样的:需要代码操作。 The good point -- it should be easier to do compared to altering URLs (+ much easier to read/understand what is going on). 好处是-与更改URL相比,它应该更容易实现(+更容易阅读/理解正在发生的事情)。

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

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