Fix - php-cgi.exe quits after exactly 500 hits on Windows or 502 bad gateway errors

I had this issue on Windows.

I fixed it after reading two threads on stackoverflow.

My current Caddyfile is:

:2015 {
	root C:\sites\1
	on startup php_cgi.bat &
	fastcgi / 127.0.0.1:6545 php
}

php_cgi.bat:

:start
	SET PHP_FCGI_MAX_REQUESTS=0 
	C:\php\php-cgi.exe -b 6545

Another option if you’re worried on memory leaks in php_cgi.bat:

:start
    C:\php\php-cgi.exe -b 6545
    goto start

Other suggestions in these stackoverflow issues may work too, but this works for me on Windows 7 x64.

Though I would share it in case someone finds it helpful.

@ITSecMedia and @pwhodges you may find it helpful.

@matt I suggest adding a note on it in the docs. Maybe here:
https://caddyserver.com/docs/fastcgi

Ref:

@Whitestrake, @tobya, @Alan_Bradshaw I think you may find this thread helpful.

1 Like

cheers magikstm :wink: