504 Gateway Time-out during POST

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

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
:slight_smile:

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 :-/

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 :-/

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?

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

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.

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:

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.

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.

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

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

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>

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 :wink:

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

Thanks.

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

e. g.

http://www.php.net/manual/en/session.configuration.php#ini.session.save-path
http://www.php.net/manual/en/session.configuration.php#ini.session.entropy-file

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’!

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 ?

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

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

Thanks for your assistance

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

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

BR

Aleks

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

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

It’s vbulletin (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 ?

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?