Simultaneous debugging sessions in PhpStorm

When building web applications with multiple tiers, we can have a situation in which frontend PHP code calls into backend PHP code. It’s easy to use remote debugging on the frontend, but what if we wanted to debug both sides at the same time?

By default, PhpStorm accepts only one debugger connection at a time. There are several reasons for this, for example when making extensive use of AJAX a lot of incoming debugger connections may be created making debugging virtually impossible.

On a per-project basis, we can enable support for having more than one debugger connection. Through the File | Settings menu and then PHP | Debug, we can beef up the maximum number of simultaneous connections from 1 to a larger number.

Note that for debugging to work, we must configure PHP and enable the PHP Debug Connections listener in PhpStorm. More on this can be found in our new tutorials space.

Let’s put this to the test. As an example, I’ve created two simple files where frontend.php makes a call to backend.php.

After placing a breakpoint in both files, we can run our code on our local webserver and call into frontend.php from a browser. When stepping through the code, PhpStorm will open a new debug session for backend.php once it gets called by the frontend code.

As always, we appreciate your feedback in the comments below or in our forums!

Develop with pleasure!
– JetBrains Web IDE Team

This entry was posted in Cool Feature and tagged , , . Bookmark the permalink.
  • goyote

    I use to debug an application hosted inside a virtual machine, now no matter what my settings I can get a connection to work. Does jetbrains offer any paid support?

  • Ronald

    Thanks for that tipp. I was using a VM with the frontend there deployed and calling the backend for debugging. And that is pain that way. I’ll try that tomorrow.

  • Faisal

    This does not seem to work if the frontend and backend code bases are in separate PHPStorm projects.

    Do we have to have all code bases in the same PHPStorm project in order to debug a tiered application?

    • Maarten Balliauw

      If you have on PhpStorm instance listen for connections, it will ask you to locate the other project’s files if needed and use those for debugging.

  • Marco Zirino

    I use Behat to run a web-broswer via Selenium to do my testing. Also, I use angularjs on the front-end. I often run into situations where I want to run the application via Behat to a certain state, and then debug my javascript issues. To do this, would I first start a Javascript debugging session? If so, how do I attach my Selenium driver to this instance. Second, How do I get my behat instance to pause at the right point? Ideally, I would like to have the Behat pause while I debug javascript on the browser.