Breakpoints in two applications using the same codebase using Xdebug

I installed Xdebug on a local Vagrant instance running Ubuntu. It works as expected, and I can set breakpoints in my application.

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

Tree illustration

codebase/ app/ root api/ root 

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

If now I set a breakpoint in some code for the API, and then find https://local.myapplication.com/some/action/that/triggers/the/api/code , then the breakpoint is only triggered if I do not initialize the Xdebug session for the first application, that is, I do not set the request parameter XDEBUG_SESSION_START . If set, my breakpoint is ignored.

There is a definite drawback. If I have a breakpoint in the application and API, I cannot start both at the moment. Either I can call application breakpoints or API breakpoints.

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

 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 a fix? Any answers / comments appreciated!

+8
debugging php vagrant xdebug sublimetext3
source share
2 answers

Two options. If the first (easier) does not work, the second will certainly be.

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

In php.ini add the following xdebug options:

 xdebug.remote_autostart = 1 

Look here

2 - simultaneously start two Xdebug sessions.

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

For example:

  • Your "application" β†’ port 9000
  • "Internal API" β†’ port 9001

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

 ini_set('xdebug.remote_port', '9001'); 
+1
source share

Use conditional breakpoints . You can make them depend on any PHP code. For example. set a constant for each entry point and check it. Or check the request url.

0
source share

All Articles