5

Is there a way to disable the read timeout for FastCGI? (fastcgi_read_timeout)

Setting it to zero does not work and just causes an immediate timeout.

  • Nginx 1.0.5
  • PHP-FPM 5.3.6-13ubuntu3.6

The reason I need to get around the timeout is because of the way reports are generated by the system we use. Since forking is not possible in PHP-FPM (pctnl_fork() is disabled), the report processing is done as soon as the request is sent. This causes the read to hang until the processing is completed by the system.

Kevin Herrera
  • 175
  • 1
  • 5
  • I have a feeling you're actually trying to solve a problem the wrong way. Could you describe the issue or elaborate why you need longer (or indefinite) timeout length? – Sašo May 04 '12 at 17:09
  • I updated the OP with an explanation. – Kevin Herrera May 05 '12 at 20:28
  • Not sure if your setup will allow it, but you should be able to use [`exec()`](http://ca2.php.net/manual/en/function.exec.php) to launch a new copy of php (essentially running your report in the background, and closing out the original request). Something like `exec("php file.php > output.txt 2>&1 &");` (add `echo $!` and capture the output if you need the PID to monitor its status). – cyberx86 May 06 '12 at 01:48
  • @Sašo, this is also issue when you're working with PHP & xdebug. – ptkoz Feb 12 '16 at 14:03

2 Answers2

5

It looks like your only option is to set fastcgi_read_timeout to a really big value (like 1h or 1d).

mgorven
  • 30,615
  • 7
  • 79
  • 122
0

How I would go about solving the problem:

  1. When user sends a request to generate report, use exec("php report.php") to run the report generation script in CLI mode. Use some identifiable information as aruguments, of course.

  2. Load a 'Please Wait' page for the user, using AJAX to check if the report is done using ps w. Look for script name and arguments used.

  3. Once done, redirect to report page.

This way you prevent users from mashing refresh if the wait becomes too long (effectively making it even longer), while also informing the user that the process is still running.

Sašo
  • 1,494
  • 2
  • 10
  • 14
  • 1
    The problem with this suggestion is that the report generation tool was not designed to be executed from the command line. There would be a whole lot of hackery involved in just passing the information needed by the report generation tool to actually produce the report. – Kevin Herrera May 14 '12 at 15:46