Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

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:

frontend.php file:

<?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:

<?php

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

$person = new Person();

$person->name = 'Something';
$person->email = '[email protected]';

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:

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).

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 xdebug configuration from phpinfo and xdebug configuration in PhpStorm xdebug configuration in PhpStorm

Upvotes: 1

Views: 1716

Answers (1)

LazyOne
LazyOne

Reputation: 165108

1. Settings | PHP | Debug | Max simultaneous connections -- should be more than 1. You already have it set.

2. xdebug.remote_autostart should be 1 / on. This will tell xdebug to attempt to debug every single request regardless of debug cookie/parameter.

This is needed as your 2nd script will not receive the same cookies/parameters as original script (as it is technically separate request).

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.

The alternative approach (in your specific case) would be adding xdebug GET parameter (e.g. ?XDEBUG_SESSION_START=1) into URL when calling for 2nd script. This will tell xdebug to debug this request. 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). Quite often this is not desired.

Yet another alternative is to set breakpoint programmatically by adding xdebug_break();. This should trigger debugger even without those extra params/cookies or remote_autostart setting.

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).

Upvotes: 5

Related Questions