Script will not stop executing until they reach php timeout itself.

The 504 error are generated on the gateway / proxy itself, it's not coming from the php process.

It's because this, if you have an Apache with Apache-mod-php you will never receive this error, because there's not a proxy.

Extending the explanation, think as follows:

You have a PHP process. The PHP process can be a PHP-FPM, PHP-CGI, or Apache-MOD-PHP. On this process, you have a timeout (configured on php.ini or with a ini_set).

The PHP proxy gives a response in the allowed time (aka: if you have a set_time_limit(600), your PHP process can be running up to 10 minutes).

Without relation on this sentence, you can have another process waiting for these response: That's the case of a apache (configured to contact to php by cgi or fpm), a nginx, a lighthttpd, and others. That's not the case of a apache configured by apache-mod-php. This second process, have a new timeout (proxy_timeout), configured on the vhost / general server app config. That's the time the program will wait for a response from PHP processing engine.

The last sentence, can be repeated on each proxy / gateway.

Think on this scenario:

haproxy (Timeout 1) --> Nginx (Frontend / cache) (Timeout 2) --> Apache (Timeout 3) -> PHP-FPM (PHP Timeout / set_time_limit).

And a very simple scenario:

Apache (with apache-mod-php) (PHP Timeout / set_time_limit).

Each timeout appearance (except the PHP Timeout itself) is a probable origin of a 504 HTTP gateway timeout error.

Answer from Sakura Kinomoto on Stack Exchange
🌐
H3XED
h3xed.com › web-development › php-and-apache-504-gateway-timeout-troubleshooting-and-solutions
PHP and Apache 504 Gateway Timeout Troubleshooting and Solutions - H3XED
If you haven't yet, make sure both max_execution_time and max_input_time in your php.ini file are set to a sufficient number of seconds. For example: max_execution_time = 600 max_input_time = 600 · If you have PHP set correctly, it may be Apache's config that is timing out. The setting that ...
Top answer
1 of 2
5

Script will not stop executing until they reach php timeout itself.

The 504 error are generated on the gateway / proxy itself, it's not coming from the php process.

It's because this, if you have an Apache with Apache-mod-php you will never receive this error, because there's not a proxy.

Extending the explanation, think as follows:

You have a PHP process. The PHP process can be a PHP-FPM, PHP-CGI, or Apache-MOD-PHP. On this process, you have a timeout (configured on php.ini or with a ini_set).

The PHP proxy gives a response in the allowed time (aka: if you have a set_time_limit(600), your PHP process can be running up to 10 minutes).

Without relation on this sentence, you can have another process waiting for these response: That's the case of a apache (configured to contact to php by cgi or fpm), a nginx, a lighthttpd, and others. That's not the case of a apache configured by apache-mod-php. This second process, have a new timeout (proxy_timeout), configured on the vhost / general server app config. That's the time the program will wait for a response from PHP processing engine.

The last sentence, can be repeated on each proxy / gateway.

Think on this scenario:

haproxy (Timeout 1) --> Nginx (Frontend / cache) (Timeout 2) --> Apache (Timeout 3) -> PHP-FPM (PHP Timeout / set_time_limit).

And a very simple scenario:

Apache (with apache-mod-php) (PHP Timeout / set_time_limit).

Each timeout appearance (except the PHP Timeout itself) is a probable origin of a 504 HTTP gateway timeout error.

2 of 2
1

My understanding is that the script does continue running, but stops reporting data to the client. (Not that I have the knowledge to explain it.) Here's an article that may help:

How to Fix a 504 Gateway Timeout Error in WordPress

Discussions

timeout - 504 Gateway Time-out Error on PHP Script - Stack Overflow
I coded a script for database import, it makes a few jobs on database. When I work this script, after a few minutes I'm getting "504 Gateway Timeout Error". I increased all timeout values on php.... More on stackoverflow.com
🌐 stackoverflow.com
Newest Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
Error: 504 Gateway Timeout after 60 seconds. | OpenLiteSpeed Community and News
Description: We are trying to run a PHP script that takes 300 seconds to execute. After exactly 60 seconds, the connection is closed with an error: 504 Gateway Timeout. However, the script continues to run in the background and finishes its task successfully after 300 seconds - the script is... More on forum.openlitespeed.org
🌐 forum.openlitespeed.org
November 7, 2022
php - Gateway Time-out:The gateway did not receive a timely response from the upstream server - Stack Overflow
The gateway did not receive a timely response from the upstream server or application. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. ... But I am regularly getting same error. Please help me to find out the solution. ... Save this answer. ... Show activity on this post. I encountered the same problem and I used ini_set('default_socket_timeout', 6000); to fix it. http://php... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/phphelp › 504 gateway timeout error due to php 7.4 fpm api
r/PHPhelp on Reddit: 504 Gateway Timeout Error Due To PHP 7.4 FPM API
December 30, 2022 -

So guys we were using php 7.4 fpm for api and we're getting 504 Gateway timeout. so i increased the memory_limit from 128M - 512M which is believe is 512 Megabytes, also increased max_execution_time from 30 to 300 which i believe is 300 seconds in /etc/php/7.4/fpm/php.ini file.
but before doing that I stopped the php7.4-fpm server and when the changes done, i started it. The below php7.4-fpm error logs are before stopping the fpm and after starting the fpm.

php7.4-fpm error log:

[30-Dec-2022 03:22:38] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
[30-Dec-2022 03:26:45] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
[30-Dec-2022 03:27:28] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
[30-Dec-2022 06:24:58] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
[30-Dec-2022 07:13:10] NOTICE: Terminating ...
[30-Dec-2022 07:13:10] NOTICE: exiting, bye-bye!
[30-Dec-2022 07:24:11] NOTICE: fpm is running, pid 1146754
[30-Dec-2022 07:24:11] NOTICE: ready to handle connections
[30-Dec-2022 07:24:11] NOTICE: systemd monitor interval set to 10000ms
[30-Dec-2022 09:39:59] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

as i can see, the api is working fine now but after restarted we can see these is this pm.max_children error still occurred once. It has been 4 hours and right now while writing this these is still only that 1 error after started the fpm service. can anybody please help me regarding the error. I once tried to change these values before but it ended up breaking the php-fpm service and it was not starting at all so had to revert back the changes made to the pm.max_children parameters.

Thanks.

🌐
Stack Overflow
stackoverflow.com › questions › 16002268 › prevent-nginx-504-gateway-timeout-using-php-set-time-limit
Newest Questions - Stack Overflow
A collective where developers working with PHP can learn and connect about the open source scripting language.
🌐
Kinsta®
kinsta.com › home › resource center › blog › http status codes › how to fix the 504 gateway timeout error on your site
How to Fix the 504 Gateway Timeout Error on Your Site
March 12, 2026 - An e-commerce site that gets 50,000 visitors per month needs a lot more resources than a simple blog with the same amount of traffic. If all the server’s PHP threads are busy, they’ll build up a queue. When the queue gets too big, the server disregards old requests, which may cause the server to throw up a 504 gateway error.
🌐
10Web
10web.io › blog › 504-gateway-timeout-error
504 Gateway Timeout Error and How to Fix It - 10Web
April 16, 2026 - In case all PHP workers are busy and the queue is full, 504 or 502 errors may occur. So it’s very important to understand the exact number of workers that will best serve your needs. Depending on your website type (it can be a simple blog or an eCommerce platform that requires processing non-cached pages) you’ll need a different number of PHP workers. Increasing the number of workers allows your website to serve more concurrent requests. Another reason for a 504 Gateway Timeout error can be improper firewall configuration.
🌐
W3docs
w3docs.com › home › code snippets › php › prevent nginx 504 gateway timeout using php set_time_limit()
Prevent nginx 504 Gateway timeout using PHP set_time_limit() | W3docs
A 504 Gateway Timeout specifically means nginx stopped waiting for the PHP-FPM worker. If the worker is busy or timed out, you may need to look at other factors, such as PHP-FPM pool configuration, server resource utilization, or application ...
Find elsewhere
🌐
Quora
quora.com › How-do-I-fix-Gateway-Timeout-for-my-PHP-application
How to fix Gateway Timeout for my PHP application - Quora
Answer (1 of 3): This usually caused by a bad design approach. If there is a task which you think will usually take longer than normal php scripts, then you should separate that into two pieces (at least) 1. Main Controller code (It basically used to accept and answer the web request from browse...
🌐
InMotion Hosting
inmotionhosting.com › inmotion hosting home › support › website › website error numbers › how to fix the 504 gateway timeout error
How to Fix the 504 Gateway Timeout Error
December 31, 2025 - A 504 gateway timeout occurs when a server waits too long for an upstream response, often caused by slow PHP scripts, database delays, or misaligned timeouts. For WordPress sites, fixing it involves checking logs, optimizing performance, tuning ...
🌐
HostMyCode
hostmycode.com › home › tutorials › fix 504 gateway timeout in php-fpm
Fix 504 Gateway Timeout in PHP-FPM | HostMyCode
February 9, 2026 - If these messages exist, the gateway timeout is confirmed as a PHP-FPM execution delay, not a networking issue. PHP-FPM logs reveal whether requests are slow, blocked, or crashing.
🌐
Hostinger
hostinger.com › home › how to fix the 504 gateway timeout error
How to Fix 504 Gateway Timeout error in 2025
September 9, 2025 - If the upstream server is down or unresponsive, it can directly lead to a 504 error. Web server overload. When a web server is overwhelmed with requests or running low on resources, it can slow down or halt responses entirely, leading to timeouts. Limited PHP workers. Websites with an insufficient number of PHP workers can experience delays in processing requests, causing timeouts, especially when handling multiple simultaneous requests. To prevent 504 Gateway Timeout errors, ensure you regularly monitor server loads and optimize website resources.
🌐
Server Fault
serverfault.com › questions › 535620 › php-gateway-timeout
nginx - PHP Gateway Timeout - Server Fault
September 2, 2013 - Gateway timeout is a typical error generated by proxy or load balancer (HAProxy, Pound, etc) ... Also, in /etc/nginx/sites-available/default add the following line to the location block of the server in question: ... location ~ \.php$ { fastcgi_pass ...
🌐
Wpoven
wpoven.com › blog › how-to-fix-504-gateway-timeout
How to Fix HTTP 504 Gateway Timeout Error? [12 Quick Method]
July 19, 2024 - Then just restart Nginx and PHP-FPM. ... If you use Nginx as a proxy for Apache, then in this case add the following to your nginx.conf file: proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600; Next, just restart Nginx. ... If you constantly face an HTTP 504 gateway timeout error and nothing helps to fix it, contact the hosting technical support.
🌐
PhoenixNAP
phoenixnap.com › home › kb › web servers › 504 gateway timeout: what it is and how to fix it
504 Gateway Timeout: What it is and How to Fix it
May 29, 2025 - The error indicates that the server acting as a gateway or proxy failed to receive a prompt response from an upstream server required to fulfill the request. There can be multiple causes of the 504 Gateway Timeout error.
🌐
GetPageSpeed
getpagespeed.com › home › blog › 504 gateway timeout nginx: how to fix it
504 Gateway Timeout in NGINX: Fix It in 5 Minutes (2026)
June 7, 2026 - In 99% of 504 Gateway Timeout NGINX cases, proxy_read_timeout is the culprit. Your backend is slow to respond, not slow to accept connections. ... For PHP applications, fastcgi_read_timeout is almost always the one to increase.
🌐
Caddy Community
caddy.community › help
504 Gateway Timeout PHP - Help - Caddy Community
May 7, 2024 - 1. The problem I’m having: I’m getting a 504 Gateway timeout after 60 seconds even though my timeouts are set to 14400 seconds. PHP max_execution time and input time are both 14400 seconds fpm doesn’t have terminate ma…
🌐
Laravel News
laravel-news.com › home › laravel tutorials › debugging gateway errors
Debugging Gateway Errors
August 14, 2023 - You'll sometimes hit Gateways errors, usually 502 Bad Gateway or 504 Gateway Timeout. These are errors Nginx returns when it sends a request to PHP but PHP is returning some error saying it can't process the request.