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 ExchangeScript 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.
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
timeout - 504 Gateway Time-out Error on PHP Script - Stack Overflow
Newest Questions - Stack Overflow
Error: 504 Gateway Timeout after 60 seconds. | OpenLiteSpeed Community and News
php - Gateway Time-out:The gateway did not receive a timely response from the upstream server - Stack Overflow
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.
You can increase maximum execution time in php.
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
Write an info file on your server containing
<?php phpinfo();
View the file in your browser and check the max_execution_time

If it's 0 then there is something different to do else make sure you changed on correct ini file.
You can also check your ini file location

If you still can't fix it please reply :)
I encountered the same problem and I used ini_set('default_socket_timeout', 6000); to fix it.
http://php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout
"Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
This would indicate something is not configured properly on the server.
Can't follow why you think this is a CloudFlare issue right now (from the tag). Are you getting a CloudFlare error message at all?