502 Bad Gateway PHP Storm but Interpreter and executable are set

liljoshu picture liljoshu · Dec 1, 2015 · Viewed 15.7k times · Source
  • OS: Windows 7 - 64 bit
  • PHP: Standalone php.exe (PHP ver 5.5)
  • PHPStorm Version: 10.0.1

All the advice I see on getting past the 502 Gateway error in PhpStorm involve just making sure you've got your Interpreter and executable set. I'm using the standalone php.exe (http://windows.php.net/download#php-5.5 VC11 x86 Thread Safe (2015-Oct-01 01:25:56)) and have everything set to PHP 5.5

enter image description here

I am honestly confused why I'm still getting 502 errors.

I've run it multiple times, and it did run once (there were no changes from instances before or after) which I found profoundly odd, but only for one page load and it was not a repeatable occurrence.

Edit: Realized one difference when I opened up another project to compare to. The one time it did work, the right-click context menu looked different. The other project is debugging just fine. What makes the difference? What gives? Both projects are using the same interpreter.

... Also found that going back to the working project, the additional context menu item disappeared.

enter image description here

Edit 2: Still problem hunting... found that certain files will run right when I start PHPStorm and will have that context menu. Other files, however, won't at startup of PHPStorm. If I I try to debug a file without the addtional menu, the server will give 502 and then the "good" files won't have the extra menu. If I start with one that has the extra context menu first, it will run, although if I follow with one doesn't, the first file ceases working. I feel like I'm making "progress" but I am also getting more confused, especially since each of these times I try to run a different file, it asks me "[x] is a single-instance run configuration. Are you sure you want to stop the running one?" At which point I click "Stop and Rerun". I would figure that the ones giving 502 wouldn't have anything carrying over to the "good" files if things are stopped and rerun... but that appears to not be the case.

Edit 3: Wondered if maybe my interpreter setup might be bad, so I grabbed securewamp ( http://securewamp.org/en/ ), got the portable version, setup, used default setup with xdebug added on (this version: php_xdebug-2.4.0rc1-5.4-vc9.dll) and exact same problem.

I'm even at a loss of additional things to check.

Edit 4: Extra sure that it's something in PHPStorm now. One of the php files that wasn't ever working, I opened directly with the php.exe and it worked fine. It has to be some setting in phpstorm that I"m missing, or some broken function.

Edit 5: Following a trail of potential causes, tried the Run > Validate Debugger tool. Path and URL left to default (no reason to change them), and attempt to vlaidate results in "Please check that web path to validation script is correctly configured" and lists my directory.

Edit 6: Validation was only picking up on 127.0.0.1 because that's what SecureWAMP was running on. Turning off its server results in "failed to execute validation script: 'Connection refused: connect'.

Edit 7: As pointied out by LazyOne, my files in the first image are two different filetypes (php and html). I have done it with .php files on both sides, I just grabbed two of the files I was currently working in for the screenshot. Here's an example of one of the php's. enter image description here

Edit 8: I think I'm finally getting a solid pattern to when it works and when it doesn't. The context menu thing was a red herring. Ones without a submenu will work just fine when conditions are met.

  • A. A file that works (so far no pattern noticed yet for working files vs nonworking, in fact, one working and one nonworking file have the exact same code) must be selected.

  • B. Cannot, under any condition, "Stop and Rerun" a file as this will cause the file to hit bad gateway afterwards.

  • C. You can't open up a nonworking file. If you do, current server hangs and will continue to hang until a "stop and rerun" is run on a different file, after which all open files will get the bad gateway error. Opening a non-working file will cause currently working files to get the bad gateway error.

  • D. To get working files working again after C or D requires restarting system.

Edit 9: Was fiddling around with the validate debugger configuration tool, and finally got it to give me a different answer (feel silly for it, actually, just had to include the targeted directory in the url to the validation script even though I thought the site was hosting straight from that directory. Oh well. Anyway, had one error, not sure if it's the cause of my issues or not, but will research it. enter image description here

Edit 10: Adding to php.ini to address above error... xdebug.remote_enable=1

Edit 11: No real benefit seen from the added line.

Edit 12: Posting requested screenshot of browser enter image description here

Edit 13: Updates to the EAP (10.0.2) version of phpStorm. It appears the same result so far, although now at least the console is showing me the error too instead of just the webpage. Also tried running completely through SecureWAMP's apache server only to find out there's something blocking me from changing away from the default htdocs directory.

enter image description here

Answer

Anne Gunn picture Anne Gunn · Oct 6, 2016

FWIW, I think this could be as simple as a timing-out problem.

My environment is very similar to the OPs, Win764, PhpStorm 10.0.4, PHP 5.5.27.

I have some F3 automated tests where I see the 502 Bad Gateway error frequently when I run the test code 'in the browser' using one of the little icons in the toolbar that floats to the upper right of my code. (See image below.)

For some of my test pages, the error seems to be first-time-only. Run once, fails, run again, works ok. Others seem to require 2 or 3 runs before they will work. But I have a couple that I've never seen work in the browser.

OTOH, if I right-click in the code window for any of these pages and debug, the code runs fine whether I let it run all the way through or walk it line by line.

Clearly, my tool setup is not wrong. Some tests can and do run from the browser every time.

What I THINK is happening is that the likely-to-fail tests execute fairly heavy db queries. And my php interpreter is aggressively timing out my requests when I run them in the browser.

But, each time a page runs and times out, one or more of its queries gets cached and the next time I run it, the page is faster. Eventually, for the ones that will run at all, enough of the db work is cached so the page can get in under the wire and finish before the time limit.

So that's my theory. What I haven't found is where and how to change the interpreter timeout interval. That is, the timeout interval when run from PhpStorm. I do already have

max_execution_time = 300

in my php.ini file and can see that it is set when I use phpinfo(). But I have to believe that it is getting overridden when the interpreter is run from PhpStorm.

Update -- possible fix: So even though my php.ini file has that max_execution_time setting, I tried looking at my php interpreter settings as described on this PhpStorm support page, steps 1 and 2. There my max_execution_time was 0. So, I added a setting for it using the UI on that page to be the same 300 I have in my php.ini. (Then I closed and re-opened PhpStorm -- a big of old-programmer paranoia.) So far, I've seen one bad gateway message on my 'worst' page but even it ran the second time. The others seem to all be running to completion. I'll do some watchful waiting and see if this 'fix' does me any good long term.

(And, before anyone feels compelled to point it out: Yes, caching queries is a terrible idea for automated tests. Gotta fix that -- but only after I figure out how to extend the interpreter timeout so my tests can succeed without caching.)

enter image description here