When you develop applications that need to communicate with each other you might need to debug two or more projects at once. You can achieve this very easily with PHP Tools for VS.
Let's say we have a PHP web site, which will be sending requests (e.g. AJAX, SOAP or anything else) to the web service. The web site will be handling the responses and do some work with it. For this scenario we will assume both are running locally (it would be similar to when run it on a remote sever).
I'll demonstrate this scenario with a simple example.
We will create one solution with two PHP Web Projects (
*.phpproj). One for the web site, let's call it just simply PHPWebProject and the second PHPWebService.
I will use a simple code:
PHPWebProject | index.php :
<?php $ch = curl_init("http://localhost:38190/"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
PHPWebService | index.php :
<?php echo "Hello World from WebService"; ?>
We want both projects to start when F5 is pressed. In the solution Properties (right click on Solution node in the Solution Explorer and choose Properties), select Startup Project tab, choose Multiple startup projects and select Action for both projects to Start.
The second step makes sure that when we press F5 both PHP web Projects will start. But that would mean two browsers would be launched. That's obviously something we don't want for PHPWebService. Let's open PHPWebService properties (right on PHPWebService node in the Solution Explorer, choose Properties). As Start Action select Don't open a page. Wait for a request from and external application.
PHP Tools would usually initiate debug session by opening your project in browser with
?XDEBUG_SESSION_START=1 query string. But PHPWebService will not open any browser on F5. So we need to instruct Xdebug to start debugging (and connect back to Visual Studio) with other means.
We can do that by adding this line
xdebug.remote_autostart = 1 to
php.ini file in Xdebug configuration section which will force it to start on every request.
There are more options available, but this one is the easiest one to use.
Put a breakpoint at the first line of code at both index.php at PHPWebProject and PHPWebService. Press F5. It will break in the PHPWebProject at the breakpoint location.
By pressing F10 you can step until the line with
Another F10 will break at PHPWebService
Press F10 twice and you'll get back to PHPWebProject
This simple scenario demonstrates how you can debug multiple projects. Both projects can be in PHP, or one of them could be written in another language, e.g. C#. It would work exactly the same.
If you have any questions, please, add them in the comments below.