3

I am hoping you all can help me out a little. I have spent about 7 hours trying to find an answer and have tried many things so far.

I have a PHP script that is used to sync files/database data between 2 servers. Before you guys ask this process is necessary for this project and must stay in place.

The script basically finds all files in a directory that have changed in the last 72 hours and SFTPs them to the other server, replacing any files needed. It then creates a copy of the backing database, removes certain tables/rows, changes others and exports a .sql file. It then SFTPs this .sql file to the other server and calls an include on a file on the 2nd server that imports the .sql file replacing the existing database with updated data.

All of this works...

The issue is that no matter what changes I make to the Apache config the script always gives me a 503 error after 30 seconds, every time (between 30.02 and 30.04 seconds to be precise). However, the PHP script continues to run and successfully completes all operations, including writing to the log file, in about 60-61 seconds. There is nothing in the Apache logs referencing any kind of error at all either.

I have checked all .conf files used and none of them mention a 30 second timeout. In my httpd.conf I have added these lines:

TimeOut 300
ProxyTimeOut 300
KeepAlive On
KeepAliveTimeout 60

I also have set the max_execution_time and memory_limit on the php script to 120 and 2048M, respective, to be sure to rule that out during testing.

The page is supposed to display a success message to the user with a report of what was changed/updated. However with the 503 error I am not able to do this. So I am looking to get rid of this 503 limitation so it can properly display the end result of the sync. I am not too familiar with Apache configuration to be honest so any help/ideas on what would cause this/where to look would be much appreciated!

Thanks in advance!

MelArlo
  • 71
  • 7

2 Answers2

2

After trying many, many things I was able to find out what the specific cause was. It turns out this was caused by the proxy timing out. Here is a link to the answer that explained what to add to the vhost conf file.

In short, here is the answer for future visitors:

For the latest versions of httpd and mod_proxy_fcgi you can simply add timeout= to the end of the ProxyPassMatch line, e.g.:

ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1 timeout=1800

For older versions it was a little more complicated, e.g.:

<Proxy fcgi://127.0.0.1:9000>
  ProxySet timeout=1800
</Proxy>
ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1
Community
  • 1
  • 1
MelArlo
  • 71
  • 7
0

Not sure if you tried this, but I think you may need to adjust max_execution_time in the php.ini that Apache uses. On many distributions it defaults to 30.

http://php.net/manual/en/info.configuration.php#ini.max-execution-time

bigmandan
  • 395
  • 3
  • 12
  • Thanks for the idea @bigmandan however I have already set that to 120. The script takes just over 60 to complete so that shouldn't be an issue. – MelArlo Feb 17 '16 at 17:34