fast-cgi-client icon indicating copy to clipboard operation
fast-cgi-client copied to clipboard

How to enable Xdebug Remote Session in Async Request?

Open dreeh opened this issue 6 years ago • 4 comments

Is there a possibility to activate debug session with xdebug in fired async request? I've tried to set XDEBUG_SESSION_START POST var and some environment settings, but without success.

Did anyone found a solution?

dreeh avatar Mar 18 '19 14:03 dreeh

@dreeh Thank's for the question.

I have some too: 😄

  • Is the php-fpm endpoint on the same machine as your caller or on a different one?
  • Can you provide your Xdebug ini settings from the php-fpm endpoint?
  • Can you provide some info about your setup (OS, vagrant box, docker(-compose) config, local machine, PHP version, Xdebug Version, version of this library)?
  • Can you provide a snippet of your calling code using the Client & PostRequest classes from this library? (I'd like to see how you call the endpoint)

hollodotme avatar Mar 18 '19 14:03 hollodotme

Are you using Xdebug's remote_connect_back feature? If so please note that you also have to set the HTTP_X_FORWARDED_FOR-header in the fpm-request.

bcremer avatar Mar 18 '19 14:03 bcremer

I use following configuration in xdebug.ini and debugging works well with multiple session.

zend_extension=xdebug.so xdebug.default_enable=1 xdebug.remote_enable=1 xdebug.remote_host=${HOST_IP} xdebug.remote_port=10000 xdebug.remote_autostart=1 xdebug.idekey=PHPSTORM xdebug.remote_log=/tmp/xdebug-remote.log

You have to ensure that your IDE also use port 10000 for incoming connection. There is a client example where you can find all settings

  • https://github.com/mfuehrer82/fast-cgi-client-example

mfuehrer82 avatar Mar 18 '19 15:03 mfuehrer82

@mfuehrer82 : this is not very helpful. Is there no special thing needed to start debugging in (sub)request?

@hollodotme :

PHPStorm is starting debug session in main thread, but not in request.

  • Is the php-fpm endpoint on the same machine as your caller or on a different one?

Yes, all is on the same machine.

  • Can you provide your Xdebug ini settings from the php-fpm endpoint?

zend_extension = /usr/lib/php/20160303/xdebug.so debug.idekey = phpstorm-xdebug xdebug.remote_connect_back = On xdebug.remote_enable = On xdebug.remote_handler = dbgp xdebug.remote_host = 127.0.0.1 xdebug.remote_log = "/var/log/xdebug.log" xdebug.remote_port = 9000

  • Can you provide some info about your setup (OS, vagrant box, docker(-compose) config, local machine, PHP version, Xdebug Version, version of this library)?

PHP 7.1.26-2+0~20190216175258.13+jessie~1.gbpc20626 (cli) (built: Feb 16 2019 23:23:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.26-2+0~20190216175258.13+jessie~1.gbpc20626, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

Debian, no docker, no vagrant:

Distributor ID: Debian Description: Debian GNU/Linux 8.11 (jessie) Release: 8.11 Codename: jessie

  • Can you provide a snippet of your calling code using the Client & PostRequest classes from this library? (I'd like to see how you call the endpoint)

      $content = http_build_query(
          [
              'XDEBUG_SESSION_START' => 'phpstorm-xdebug'
          ]
      );
    
      $request = new PostRequest(..., $content);
      $request->setCustomVar('PHP_IDE_CONFIG', getenv('PHP_IDE_CONFIG'));
      $request->setCustomVar('XDG_SESSION_ID', getenv('XDG_SESSION_ID'));
      $request->setCustomVar('SSH_CLIENT', getenv('SSH_CLIENT'));
      $request->setCustomVar('SSH_CONNECTION', getenv('SSH_CONNECTION'));
      $request->setCustomVar('XDG_RUNTIME_DIR', getenv('XDG_RUNTIME_DIR'));
      $request->setCustomVar('XDEBUG_CONFIG', 'idekey=phpstorm-xdebug');
      $request->setCustomVar('XDEBUG_SESSION_START', 'phpstorm-xdebug');
      $request->setCustomVar('HTTP_X_FORWARDED_FOR', '172.29.9.149');
      $request->setCustomVar('REMOTE_ADDR', '172.29.9.149');
    
      $connection = new UnixDomainSocket(...);
      $client = new hollodotme\FastCGI\Client($connection);
      $client->sendAsyncRequest($request);
    

dreeh avatar Mar 19 '19 17:03 dreeh