0

I'm using PhpStorm 2021.1.3 as an IDE with XAMPP as a PHP7.4 engine. I have installed Xdebug 2.9.2, and it works properly since I can start the debugger on specific PHP scripts.

My issue is that I have an HTML form in a PHP webpage (let's call it "mainpage.php", which sends its data to another PHP file (let's call it "analyze.php").

The issue is that if I start the debugger on that other PHP file ("analyze.php"), it doesn't get the GET/POST data, since I didn't use the form at all. Is there a way to pass the GET/POST data when launching the debugger?

I've looked into the run configurations, but they only seem to mention PHP options, and not GET/POST data.

I tried using the HTTP Request, but the only examples I've seen use actual web hosts and production environments, as far as I could tell. I only have this XAMPP development environment at the moment. My PHP files are not in the www folder of XAMPP, since PhpStorm seemed to have no problem so far copying the file at the right place when needed.

Any idea where I should look for?

leftcursor
  • 53
  • 7
  • 1) [PHP Request](https://www.jetbrains.com/help/phpstorm/run-debug-configuration-php-http-request.html) type of Run/Debug Configuration allows to use POST (both execute and debug). 2) You can write your payload using **HTTP Client** and [debug it](https://www.jetbrains.com/help/phpstorm/http-client-in-product-code-editor.html#debug-http-requests) 3) Or you can send such requests from Postman: https://stackoverflow.com/a/19147935/783119 (PhpStorm must be waiting for debug connection at that point already) – LazyOne Jun 10 '21 at 00:54
  • 1
    It may be a silly question, but why don't you place your break-point on the form handler page _analyze.php_, and submit the form? All the post/get data will be present then. – waterloomatt Jun 10 '21 at 01:23
  • @waterloomatt : It is considered two independant PHP scripts. PhpStrom/Xdebug doesn't see the link between the two web pages, and so doesn't consider the breakpoints in the second page, AFAIK. – leftcursor Jun 10 '21 at 01:28
  • It shouldn't matter. PHPStorm should see the form submit (post/get) and catch it. You should be able to navigate around your application (links, forms, ...) and PHPStorm will catch all those requests. If that is not working then there may be a problem with your setup. Are you using a browser extension to trigger the debug session? Some of those extensions require you to tell it which method (get,post, both) to expect and also which page (this page, next page, etc.). Ex. https://chrome.google.com/webstore/detail/zdebug/gknbnafalimbhgkmichoadhmkaoingil – waterloomatt Jun 10 '21 at 01:34
  • @LazyOne : Ok, I found that PHP HTTP Requests are different from HTTP Requests, and that you can add the PHP one by clicking on the topleft "+" in the Run/Debug Configurations. Running the PHP HTTP Request results only in 404 error however, so something must be off in the config. – leftcursor Jun 10 '21 at 01:35
  • @waterloomatt : I'm the "Xdebug helper" Chrome extension, but it doesn't work. PhpStorm receives the debug request, but then sends an error message. I've read that it stopped working mid-2020 after one of PhpStorm's update, but I can't find the bug ticket now. PhpStorm used to send a warning the Event Log about server names or something, but now I'm not getting anything. – leftcursor Jun 10 '21 at 01:48
  • @waterloomatt : Found the issue : https://youtrack.jetbrains.com/issue/WI-54542 Seems that a fix will be available soonish. – leftcursor Jun 10 '21 at 01:51
  • 1
    @leftcursor So why do you use PhpStorm's built-in very simple/limited web server and not full Apache from your XAMPP? Use proper Apache -- it will always be more powerful / similar to real deployed site than any built-in web server. As I understand you just do not know how to tell PhpStorm to use custom URLs instead of built-in web server... https://www.jetbrains.com/help/phpstorm/installing-an-amp-package.html#integrating-xampp – LazyOne Jun 10 '21 at 08:02
  • @leftcursor If you use Xdebug helper browser extension (or a [bookmarklet](https://www.jetbrains.com/phpstorm/marklets/)) .. it sets Xdebug cookie (that acts like "debug me" flag) that **is** getting passed from a page with the form to fill to the page where it sends the POST data (doing that all the time). Have a look at ["zero-config debug"](https://www.jetbrains.com/help/phpstorm/zero-configuration-debugging.html) Also: https://www.jetbrains.com/phpstorm/documentation/debugging/ and https://www.jetbrains.com/help/phpstorm/debugging-with-phpstorm-ultimate-guide.html – LazyOne Jun 10 '21 at 08:25

1 Answers1

0

Ok, thanks to @waterloomatt I managed to find a workaround. The crux of the issue in my case is this PhpStorm bug: https://youtrack.jetbrains.com/issue/WI-54542 Therefore, this answer will probably be irrelevant once this bug is resolved.

Here's the solution on Linux :

Step 1 : Create a server on PhpStorm.

In File->Settings->PHP->Servers, click on the "+" symbol to add a new server. Fill the server infos. How to create a server on PhpStorm The port is 63342, which is the port PhpStorm uses for running the code. Note that I gave this server the name "localhost63342". This detail is important.

Step 2 : Launch XAMPP normally.

Launch XAMPP as you do normally. The issue is with PhpStorm, not XAMPP.

Step 3 : Before launching PhpStorm, add an environment variable

Open a command prompt, and run the following command:

export PHP_IDE_CONFIG=serverName=localhost63342

Note the server name, which is the same as the name of the server we defined in PhpStorm.

I could make that environment variable more permanent, but since it is a soon-to-be-resolved PhpStorm bug, I think that'll do.

Step 4 : In the same command prompt, launch PhpStorm

We defined an environment variable, which is valid as long as the command prompt remains open. We then can launch PhpStorm with this command prompt. In my case, with the following command:

./$HOME/phpstorm/PhpStorm-203.7148.74/bin/phpstorm.sh

Step 5 : Launch a debugging session

My Chrome browser already has the "Xdebug helper" extension: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en That extension is already configured to use the PHPSTORM IDE Key, as shown here:

Xdebug helper configuration

In PhpStorm, I put a breakpoint where I want in my code. I click the button to make PhpStorm listen for PHP Debug Connections. I then launch the code from the page I want using the launcher button (Chrome is Alt+F2 on my computer).

The code runs normally, and I can navigate from page to page. When, on a specific page, the code hits a PHP breakpoints, the code is suspended, and I can execute it line by line using PhpStorm's debugger. Since I filled the forms to get to this page, I get the GET/POST data.

It's not as direct as a PHP HTTP Request I suppose, but it works.

leftcursor
  • 53
  • 7
  • Why not use Apache from XAMPP and avoid PhpStorm's built-in web server (that has issues). But if this works for your and you like it ... then all good. – LazyOne Jun 10 '21 at 17:14
  • @LazyOne : I'm not sure I understand. You mean sending HTTP requests using the command line ? How would one do that ? And how would that link to the PhpStorm debugger (so I can execute the code line by line) ? – leftcursor Jun 10 '21 at 20:34
  • I mean: 1) why use PhpStorm's built-in web server and not Apache from XAMPP? A proper web server will always be better. – LazyOne Jun 10 '21 at 20:54
  • 2) I do not see anything about "command line" in my comments. You can debug current way (open a form page, fill and submit it to debug the page that handles the form data )-- **no issues here at all** (you will just need to re-enter the form data every time) . It just the other 3 options (HTTP Request, HTTP Client and Postman) can also be used for debugging and allow repeating the same request much easier (as you will be sending request straight to the debug target and request data will be already entered/saved) – LazyOne Jun 10 '21 at 20:56