Caddy FastCGI PHP crashes again and again on Windows

I’m working on a Statamic website project using Caddy FastCGI PHP as replacment for a local Apache installation
I just have to reload some pages a few times in my browser and I get those error messages

09/Nov/2016:21:26:44 +0100 [ERROR 502 /index.php/] http: request method or response status code does not allow body
09/Nov/2016:21:29:30 +0100 [ERROR 502 /index.php/] read tcp> wsarecv: An existing connection was forcibly closed by the remote host.

It seems that some return values cause the FastCGI addon to crash … or whatever …

The moment that happens I’m forced to shutdown Caddy and restart because nothing works anymore.

Anyone here with the same problems?

Can you post your full caddyfile?

Are you using a single fastcgi instance to serve multiple hosts?

Do these hosts call each other (eg do they request data via file_get_contents or curl from each other?)?

The reason I’m asking is that I have been having similar issues with sites hanging when using fastcgi with php

Happens more or less everywhere.

Currently switched to NGINX for local development because Caddy freezes too often on my local dev machine.
Hit F5 in your browser to refresh a couple of times and it stucks.
Tried it without and with pool setting, no difference …

No special settings, id say… file_get_content, not that I remember this second
I had to do a full source review to see as I can’t remember right now.
Some JS ajax calls and an ordinary PHP website.

localhost:80, {
    tls off
    browse /
    errors caddy_error.log
    # log caddy_access.log
    startup php-cgi -b &
    fastcgi / php {
        ext .php
        split .php
        index index.php
        pool 100
    markdown / {
        ext .md

    rewrite {
        regexp .*
        ext    /
        to     /index.php/{1}

I have another Caddy hosting on a VPS, there I host a static HTML website with 1 x single PHP file which does indeed use file_get_contents ( just a few lines of code ) and all few days I have to restart Caddy as a PHP error is in a non recoverable state and PHP doesn’t work anymore, although Caddy instance still runs.

What request is being made to Caddy that it’s trying to return a 502 on, exactly? With that rewrite any request to any path without a file extension could be getting directed to fastcgi.

Small note but

    fastcgi / php {
        ext .php
        split .php
        index index.php
        pool 100

is a tad redundant - the php preset is equal to the first three lines in the braces.

Thanks for the hint about the wrong setting with the [php] preset.
But even when I remove the three obsolete .php preset settings …

I just trigger F5 x 4 times and the local website doesn’t load anymore … or tries to load forever …

24/Nov/2016:11:39:31 +0100 [ERROR 502 /index.php/] dial tcp connectex: No connection could be made because the target machine actively refused it.
24/Nov/2016:11:39:54 +0100 [ERROR 502 /index.php/] write tcp> wsasend: An existing connection was forcibly closed by the remote host.

The VPS deployment stucks with a 503 error on that single php file.

No worries - but I didn’t mean to imply they were incorrect, merely redundant. Removing the three lines only shortens your Caddyfile, it doesn’t make any real changes to the configuration.

My hunch at the moment is that there are requests that are being rewritten to the php index that perhaps shouldn’t be or are otherwise malformed.

This block:

    rewrite {
        regexp .*
        ext    /
        to     /index.php/{1}

Seems really odd to me. Usually in this instance I’d expect to see something like to /index.php{uri} - you’ve got a pattern match here (the {1}) but you don’t have any matching groups in the regexp.

Played with different regex settings in a couple of projecs, statamic, grav, … copy+paste …

I’ve disabled regex completely now and … interesting hammering F5 suddenly doesn’t have a negative impact.

I thought its possible that xdebug or any php.ini settings might have an negative effect on fastcgi …

Hmmm … but now it looks like it’s fastcgi in combination with regex what causes the trouble …

There’s not a lot of things that trigger this, honestly. I’d wager it has something to do with this, that the request is a type PHP can’t handle, and it can’t return an error page because the request doesn’t allow it. If you can figure out what the specific request is, it’ll probably clarify a few things.

To clarify, I use regexp’s and php-fpm as well, including rewriting to php, in some of my sites, and have not run into this issue. My regexps are always much more specific than .*, though.

I appreciate your help. I will try to find out more about this.
I’ll get back to this thread the coming days, don’t have much time today.
Thank you!

Is this your complete caddy file? Do you have other sites loading in caddyfile also? Do the sites call each other eg does site1 call


@tobya Just one site

Caddy also has to be restarted when PHP returns an ERROR 502 /…/…php dial : connectex No connection could be made target machine refused it … After that error it doesn’t recover and I’m forced to kill / restart

On Windows, you should use PHP 7.1 as it can spawn more than 1 process.
You need to set PHP_FCGI_CHILDREN=3 (or more) before PHP launch.
Please try this, I had many 502 before this version (I used PHP 7.1 RC for quite some time)…

1 Like

@devil1591 Thank you, I’ll give it a try.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.