3

In my php application I restore db2 database. It works fine but here is one huge one 2.9GB that finishes with 500 - Internal Server Error.

I use exec() to run unix shell commands from .php - cp, db2 etc. The same error happens when running from firefox or ruby script.

I have to copy the backup image file first which takes few minutes. Then I call db2 to restored the image. For this particular database the php process finishes with above error. Then I can find this in the error log file

2012-08-02 10:25:18: (mod_fastcgi.c.2566) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9090
2012-08-02 10:25:18: (mod_fastcgi.c.3352) response not received, request sent: 2758 on socket: tcp:127.0.0.1:9090 for /wrational/tools/rationalTest.php?mode=restore&database=RATIONAL&from_database=dbb&dbbackuptype=weekly, closing connection

I set both default_socket_timeout and max_execution_time to 5660 in php.ini and confirmed that it is set by phpinfo() but it doesn't look like it helped.

Any idea how I can make this one work?

update

It looks like it dies after 40mins. The corresponding line in access.log file look like

"GET /rational/tools/rationalTest.php?mode=restore&from_database=dbb&dbbackuptype=weekly HTTP/1.1" 500 369 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20100101 Firefox/11.0"
Radek
  • 13,813
  • 52
  • 161
  • 255
  • have you tried switching from tcp based socket to a unix socket to help reduce over head. – RobertPitt Aug 05 '12 at 23:07
  • @RobertPitt: could you explain? I have not idea what you meant... – Radek Aug 05 '12 at 23:14
  • Have you considered launching the process in the background and polling for a result in an asynchronous way, rather than having your page hang for 40 minutes? – favoretti Aug 05 '12 at 23:14
  • @favoretti: I don't know how to do that. What is happening is that overnight testing starts and sometimes prior to start the test(simulating user using web browser) a database needs to be restored. So the script needs to wait that the restore finished. – Radek Aug 05 '12 at 23:26
  • Well, one approach would be to make a restore script (small shell script) that you will call using exec(), which will create a certain flag (tempfile or so) upon restore start and when done restoring. By auto-refreshing the page you can then check if restore is running and just wait, and when you see the restore_completed flag run your tests. This approach is also horrible, but a bit less horrible than hanging on "the line" for 40+ minutes waiting for 3GB database to be restored. – favoretti Aug 05 '12 at 23:35
  • I cannot see the difference between these two approaches. – Radek Aug 06 '12 at 01:35

1 Answers1

1

Looks like request_terminate_timeout option in php-fpm.ini was causing the troubles. It was set to 30 mins. I changed it to 0 and it looks good so far. Need to do more testing though.

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.  
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
Radek
  • 13,813
  • 52
  • 161
  • 255
  • Take care that some FCGI setups allow to configure as well how long the backend is allowed to take time before they report an error to apache. Just noting, this depends a lot on how the server is configured, probably something to keep in mind when the server is being changed / updated. – hakre Aug 10 '12 at 12:14