Nginx – How to properly prevent 504 Gateway Time-out

fastcginginxPHPphp-fpm

I've an script that can run for about 15 min as it is a large data migration tool.

I have the problem that either if i set fastcgi_read_timeout 9900; it never times out or if i set it to less then it times out before my script finished running.

EDIT: I have taken away the fastcgi_read_timeout 9900; from nginx.conf and setted max_execution_time = 1300; in php.ini and I get a 504 Gateway Time-out now instead of looping forever.

How can I properly set that the page should be live until the script finishes executing?

Best Answer

Why do you want to run this in the foreground? While it's possible to hack at the config files long enough for you to get this behavior, it's a very fragile configuration. Is this something that's actually outputting useful information to the user as it goes? If not, this is almost certainly suited to a background task, rather then trying to run it in one request.

Even if this is outputting to the user, have you considered running it as a background task, and piping output to the user via some asynchronous method?