# 504 Gateway Time-out during POST

**URL:** <https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964>\
**Category:** NGINX\
**Created:** [September 7, 2008, 6:53pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964 "2008-09-07T18:53:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 6:53pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/1 "2008-09-07T18:53:12Z")

</div>

Hello,

I seem to be getting a lot of 504 Gateway Time-out’s specifically when  
posting  
forms.

A sample form would be 2 textboxes and a textarea each with the word  
test in.  
This would cause the error to come up.

Any ideas what may be causing this ?

Thank you

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/2 "2008-09-07T19:11:58Z")

</div>

Just to go into a bit more detail:

I run a site with a fairly large forum. Since moving to nginx and  
php-fpm my  
server performance has got worse. I fully concede this is likely to be a  
configuration issue on my part, but it’s frustrating to say the least  
🙂

I am getting a lot of MySQL server gone away messages which whilst I  
appreciate  
can be caused by a lot of things, if when POSTing and executing PHP  
scripts at a  
very slow rate it too can cause issues like this.

Anyone else had these sorts of issues ? I’m thinking I may have to go  
back to  
Apache and PHP atm :-/

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/3 "2008-09-07T20:10:01Z")

</div>

This is affecting even non-forum pages that have to POST.

So either nginx isn’t sending to php-fpm correctly, or php-fpm is not  
functioning right for post requests :-/

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/4 "2008-09-07T20:10:38Z")

</div>

It sounds like your php-fastcgi isn’t configured like your apache or  
you are not running that many instances of them to handle your load.  
Apache automatically forked more processes as load went up. php-  
fastcgi does not so you will have to add more processes to handle the  
load. Also i would recommend using php-fpm patch to php for running  
your php-fastcgi instances.

So to ask how many processes of php do you have configured running?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/5 "2008-09-07T20:10:39Z")

</div>

On Son 07.09.2008 17:05, David wrote:

> this.  
> Do you have any errors in the php-error log or phpfm-error log?

> Anyone else had these sorts of issues ? I’m thinking I may have to go  
> back to Apache and PHP atm :-/

Well, how much time and leisure have you to solve this issue?!

BR

Aleks

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/6 "2008-09-07T20:28:18Z")

</div>

Hi Rob,

I am using php-fpm which I patched against php before installing php.

I’ve just upped my 10 to 150  
and it still 504’s.

I really don’t know what to try next.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/7 "2008-09-07T20:50:03Z")

</div>

When turning nginx logging to info I can see I am getting a lot of  
these:

upstream timed out (110: Connection timed out) while reading response  
header  
from upstream, client:

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/8 "2008-09-07T20:50:03Z")

</div>

are you using the same php.ini config as you used with apache?  
Basically look at your timeouts and such. And as Aleksandar mentioned  
is there anything in your php-fpm logs? Also what value do you have  
set for fastcgi timeout? it defaults to 1 minute i believe.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/9 "2008-09-07T20:59:25Z")

</div>

Hi,

No errors in php-fpm log.

I am happy to try and debug, just don’t like the instability for my  
users which  
I am sure you can appreciate.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 9:36pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/10 "2008-09-07T21:36:58Z")

</div>

On Son 07.09.2008 18:53, David wrote:

> Hi,
> 
> No errors in php-fpm log.
> 
> I am happy to try and debug, just don’t like the instability for my  
> users which I am sure you can appreciate.

Of course

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 9:52pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/11 "2008-09-07T21:52:48Z")

</div>

On Son 07.09.2008 19:02, David wrote:

> I think this is what you meant by php.ini’s timeout value:
> 
> max\_execution\_time = 40
> 
> Prior to moving to nginx and php-fpm I have never experienced this  
> issue BTW.
> 
> Below is a copy of my php-fpm.conf

> ```
> Sets the limit on the number of
> simultaneous requests that will be served.
> Equivalent to Apache MaxClients directive.
> Equivalent to PHP_FCGI_CHILDREN environment in
> original php.fcgi
> Used with any pm_style.
> <value name="max_children">100</value>
> 
> ```

100 WOW

> ```
> Time limit on waiting execution of single request
> Should be used when 'max_execution_time' ini option does
> not terminate execution for some reason
> <value name="request_execution_timeout">60s</value>
> 
> ```

How long is your programm running?  
Maybe you must increase this ans the max\_execution\_time

> ```
> How much requests each process should execute before
> respawn.
> Useful to work around memory leaks in 3rd party libraries.
> For endless request processing please specify 0
> Equivalent to PHP_FCGI_MAX_REQUESTS
> <value name="max_requests">500</value>
> 
> ```

How much request are done before you get the 504 error?

Which version of nginx and php?  
Please can you post a output of phpinfo()?

have you such lines in your php ini file

### 

error\_log = \<A\_PATH\>/php-error.log  
log\_errors = On  
track\_errors = On

### 

BR

Aleks

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/12 "2008-09-07T21:10:36Z")

</div>

I think this is what you meant by php.ini’s timeout value:

max\_execution\_time = 40

Prior to moving to nginx and php-fpm I have never experienced this issue  
BTW.

Below is a copy of my php-fpm.conf

\<?xml version="1.0" ?\>

```
    All relative paths in this config are relative to php's install 

```

prefix

```
    <section name="global_options">

            Pid file
            <value 

```

name=“pid\_file”\>/usr/local/logs/php-fpm.pid

```
            Error log file
            <value 

```

name=“error\_log”\>/var/log/php-fpm/php-fpm.log

```
            Log level
            <value name="log_level">notice</value>

            When this amount of php processes exited with SIGSEGV or 

```

SIGBUS …  
10

```
            ... in a less than this interval of time, a graceful 

```

restart  
will be initiated.  
Useful to work around accidental curruptions in  
accelerator’s  
shared memory.  
1m

```
            Time limit on waiting child's reaction on signals from 

```

master  
5s

```
            Set to 'no' to debug fpm
            <value name="daemonize">yes</value>

    </section>

    <workers>

            <section name="pool">

                    Name of pool. Used in logs and stats.
                    <value name="name">default</value>

                    Address to accept fastcgi requests on.
                    Valid syntax is 'ip.ad.re.ss:port' or just 

```

‘port’ or  
‘/path/to/unix/socket’  
127.0.0.1:9000

```
                    <value name="listen_options">

                            Set listen(2) backlog
                            <value name="backlog">-1</value>

                            Set permissions for unix socket, if one 

```

used.  
In Linux read/write permissions must be  
set in  
order to allow connections from web server.  
Many BSD-derrived systems allow  
connections  
regardless of permissions.  
  
  
0666

```
                    Additional php.ini defines, specific to this 

```

pool of  
workers.

```
                    Unix user of processes
                    <value name="user">nginx</value>

                    Unix group of processes
                    <value name="group">nginx</value>

                    Process manager settings
                    <value name="pm">

                            Sets style of controling worker process 

```

count.  
Valid values are ‘static’ and  
‘apache-like’  
static

```
                            Sets the limit on the number of 

```

simultaneous  
requests that will be served.  
Equivalent to Apache MaxClients  
directive.  
Equivalent to PHP\_FCGI\_CHILDREN  
environment in  
original php.fcgi  
Used with any pm\_style.  
100

```
                            Settings group for 'apache-like' pm 

```

style

```
                                    Sets the number of server 

```

processes  
created on startup.  
Used only when ‘apache-like’  
pm\_style is  
selected  
10

```
                                    Sets the desired minimum number 

```

of idle  
server processes.  
Used only when ‘apache-like’  
pm\_style is  
selected  
5

```
                                    Sets the desired maximum number 

```

of idle  
server processes.  
Used only when ‘apache-like’  
pm\_style is  
selected  
5

```
                            </value>

                    </value>

                    Time limit on waiting execution of single 

```

request  
Should be used when ‘max\_execution\_time’ ini  
option does  
not terminate execution for some reason  
60s

```
                    Set open file desc rlimit
                    <value name="rlimit_files">1024</value>

                    Set max core size rlimit
                    <value name="rlimit_core">0</value>

                    Chroot to this directory at the start
                    <value name="chroot"></value>

                    Chdir to this directory at the start
                    <value name="chdir"></value>

                    Redirect workers' stdout and stderr into main 

```

error log.  
If not set, they will be redirected to  
/dev/null,  
according to FastCGI specs  
yes

```
                    How much requests each process should execute 

```

before  
respawn.  
Useful to work around memory leaks in 3rd party  
libraries.  
For endless request processing please specify 0  
Equivalent to PHP\_FCGI\_MAX\_REQUESTS  
500

```
                    Comma separated list of ipv4 addresses of 

```

FastCGI  
clients that allowed to connect.  
Equivalent to FCGI\_WEB\_SERVER\_ADDRS environment  
in  
original php.fcgi (5.2.2+)  
Makes sense only with AF\_INET listening socket.  
127.0.0.1

```
                    Pass environment variables like LD_LIBRARY_PATH
                    All $VARIABLEs are taken from current 

```

environment  
  
$HOSTNAME  
/usr/local/bin:/usr/bin:/bin  
/tmp  
/tmp  
/tmp  
$OSTYPE  
$MACHTYPE  
2

```
            </section>

    </workers>

```

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/13 "2008-09-07T22:32:08Z")

</div>

On Son 07.09.2008 20:05, David wrote:

> Aleksandar,
> 
> I put 100 to try and eliminate too few php-fpm childs to process the  
> scripts.
> 
> The program itself times out after about a minute, but on Apache and  
> normal PHP it used to execute instantly. It’s not a looping script or  
> anything - just a couple of queries and output.

Pay attention some queries can be looooooooooong running queries 😉

> Nginx: nginx-0.6.32  
> PHP-FPM: php-5.2.6-fpm-0.5.8.diff.gz
> 
> PHPINFO: [SEO Training | Clean Slate SEO](http://www.vividdevelopment.co.uk/info.php)

Thanks.

Does you application use mysql or mysqli?  
After we have fix the 504 you should make the php setup safer 😉

e. g.

> **[session.save\_path - PHP: Runtime Configuration - Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.save-path)**
>
> The behaviour of these functions is affected by settings in php.ini. | Runtime Configuration

> **[session.entropy\_file - PHP: Runtime Configuration - Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.entropy-file)**
>
> The behaviour of these functions is affected by settings in php.ini. | Runtime Configuration

> I will add the errorlog bits to my php.ini and update when I get some  
> logs.

Yes, please.

> Thanks for your assistance

Your welcome.

Btw.: your libcurl is reallly old ‘libcurl/7.15.5’!

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 10:50pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/14 "2008-09-07T22:50:18Z")

</div>

I haven’t had any errors logged yet, but will keep an eye on it. The  
process  
itself is still taking far too long. This is a new server - I upgraded  
and took  
the opportunity to try out nginx and php-fpm. This server is  
considerably faster  
than my last.

I have setup all my scripts to run mysqli.

I’ll sort the libcurl thanks.

Is there anything I can be trying now ?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/15 "2008-09-07T22:13:20Z")

</div>

Aleksandar,

I put 100 to try and eliminate too few php-fpm childs to process the  
scripts.

The program itself times out after about a minute, but on Apache and  
normal PHP  
it used to execute instantly. It’s not a looping script or anything -  
just a  
couple of queries and output.

Nginx: nginx-0.6.32  
PHP-FPM: php-5.2.6-fpm-0.5.8.diff.gz

PHPINFO: [http://www.vividdevelopment.co.uk/info.php](http://www.vividdevelopment.co.uk/info.php)

I will add the errorlog bits to my php.ini and update when I get some  
logs.

Thanks for your assistance

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/16 "2008-09-07T23:00:51Z")

</div>

On Son 07.09.2008 20:43, David wrote:

> I haven’t had any errors logged yet, but will keep an eye on it. The  
> process itself is still taking far too long. This is a new server - I  
> upgraded and took the opportunity to try out nginx and php-fpm. This  
> server is considerably faster than my last.

Do you have got some 504 errors in the meantime?

> I have setup all my scripts to run mysqli.

Is it possible to check the runtime of the scripts?

e.g.: [PHP: microtime - Manual](http://at.php.net/manual/en/function.microtime.php)

> Is there anything I can be trying now ?

Please try to add the timing format in nginx to get a ‘normal’  
response time from php-fm

[http://wiki.codemongers.com/NginxHttpUpstreamModule](http://wiki.codemongers.com/NginxHttpUpstreamModule)

BR

Aleks

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/17 "2008-09-07T23:36:37Z")

</div>

No, no 502s, but it’s still too slow. I’m getting a lot of these isn  
nginx’s  
error-log.

I’m afraid I can’t really use the microtime function as these aren’t my  
scripts.  
This problem only seems to affect POST functions though I’ve noticed.

upstream timed out (110: Connection timed out) while reading response  
header  
from upstream

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/18 "2008-09-07T23:40:45Z")

</div>

Sorry I meant 504’s and that I haven’t received one but others have. I  
can tell  
this from my nginx error log (see error in previous post), and there is  
nothing  
in PHP error log or php-fpm error log

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 11:43pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/19 "2008-09-07T23:43:43Z")

</div>

It’s vbulletin ([vbulletin.org](http://vbulletin.org))

BTW just a thought I had when looking at my php.ini …

I moved my MySQL to a different drive and moved my mysql.sock In php.ini  
it  
looks like it’s looking at the wrong one, and /var/lib/mysql/mysql.ini  
which I  
thought was symlinked but it’s not. Could this be causing the speed  
problem ?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [September 7, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964/20 "2008-09-07T23:40:44Z")

</div>

On Son 07.09.2008 21:15, David wrote:

> No, no 502s, but it’s still too slow. I’m getting a lot of these isn  
> nginx’s error-log.
> 
> I’m afraid I can’t really use the microtime function as these aren’t my  
> scripts.  
> This problem only seems to affect POST functions though I’ve noticed.
> 
> upstream timed out (110: Connection timed out) while reading response  
> header from upstream

How about the timing log?  
Are this a public scripts or a private scripts?

[Next page](https://www.ruby-forum.com/t/504-gateway-time-out-during-post/147964.md?page=2)
