I just pushed out a new version of PHP Caddy today with a bugfix that should make it a lot more stable.
I have been using PHP Caddy as my primary development environment on my PC at work for the last month or so. At first it was wonderful – stable, fast, easy, as advertised. But as I got into the swing of using it, I started running into issues with the PHP FastCGI (php-cgi.exe) process crashing and causing
502 Bad Gateway errors – occasionally at first, but more frequently over time until it was barely usable. I have no idea what causes it to crash, and I have exhausted my google-fu trying to find a cause or solution, until now.
When I first started building PHP Caddy, I had PHP 7.0 installed, and that’s what I’ve been running since. This week, as the crash frequency was reaching unbearable levels, I decided to try upgrading to PHP 7.1. Initially, this didn’t make much difference – the crashing continued. However, in my continuing search for a solution to the problem, I found a reference somewhere that said that PHP 7.1 had added support for running multiple processes on Windows. This rang a bell, so I looked into it.
Success! Setting the environment variable
PHP_FCGI_CHILDREN=2 before starting up the PHP FastCGI process, tells php-cgi.exe to spawn multiple processes (3 total), and fixed the stability issues completely. I have now been running PHP Caddy continuously for the past two days without crashing.
If you are using PHP Caddy and have been experiencing occasional
502 Bad Gateway errors, try upgrading to PHP 7.1 and be sure to run
composer global update.