Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoints in two applications sharing the same codebase using Xdebug

I've setup Xdebug on a local Vagrant instance running Ubuntu. It works as expected and I can setup breakpoints in my application.

I have a scenario where the application makes a request to an internal API. The internal API is on the same server and same codebase.

Tree illustration

codebase/
  app/
    root
  api/
    root

The application is accessible as https://local.myapplication.com and the API is accessible locally as http://local.api.myapplication.com).

If I now set a breakpoint in some code for the API and then visit https://local.myapplication.com/some/action/that/triggers/the/api/code the breakpoint is only triggered if I do not initialise the Xdebug session for the first application, i.e., I do not set the XDEBUG_SESSION_START query parameter. If it's set, my breakpoint is ignored.

There is a certain drawback to this. If I have a breakpoint in the application and the API, I can't trigger both at the moment. Either I can trigger the application breakpoints or the API breakpoints.

I'm using Sublime Text 3 with the plugin https://github.com/martomo/SublimeTextXdebug. My Xdebug settings in php.ini are:

zend_extension="/usr/lib/php5/20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=192.168.3.1
xdebug.remote_port=9000
xdebug.remote_log="/tmp/php5-xdebug.log"

Is this fixable? Any answers/comments are appreciated!

like image 228
Kevin Sjöberg Avatar asked Jun 03 '14 18:06

Kevin Sjöberg


1 Answers

Two choices. If the first (easier) doesn't work the second surely will.

1 - Start a new Xdebug session for each http request.

In php.ini, add the following to your xdebug settings:

xdebug.remote_autostart = 1

See documentation here

2 - Run two Xdebug sessions simultaneously.

You'll need to have two separate instances of your IDE/text editor listening to xdebug - each on a different port. You can set both instances to edit the same project while their xdebug service listens on different ports.

For example:

  • Your "application" -> port 9000
  • Your "internal API" -> port 9001

To make your "internal API" run xdebug on port 9001, you can simply do the following at the start of your "internal API" script:

ini_set('xdebug.remote_port', '9001');
like image 185
user3751385 Avatar answered Nov 02 '22 15:11

user3751385