here is the fix:
in the Forge UI I updated the Max Execution Timeout (found on the PHP tab of the server).I also set therequest_terminate_timeout value in the PHP FPM at a higher value than the Max Execution Timeout
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using Laravel 8.83.25, PHP 7.4.3, and Laravel Forge deployed to AWS. When I use curl_exec() to POST a REST API at a government entity, the return can take over a minute (yea, it's the government). When the calls take a long time to return, our app times out with a 504 error (somewhere between >30 but <60 seconds) .
I've updated NGINX:
location / {
try_files $uri $uri/ /index.php?$query_string;
proxy_read_timeout 360;
proxy_connect_timeout 360;
}
and I have tried all of these techniques and nothing works:
ini_set('max_execution_time',0);
ini_set('request_terminate_timeout',0);
set_time_limit(300); // The maximum execution time, in seconds. If set to zero, no time limit is imposed.
ignore_user_abort(true); // Make sure to keep alive the script when a client disconnects.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); //Tell cURL that it should only spend 300 seconds trying to connect to the URL in question.
curl_setopt($ch, CURLOPT_TIMEOUT, 300); //A given cURL operation should only take 300 seconds max.
I have read that it may be due to an AWS CloudFront timeout value that defaults to 30 seconds but I am not that familiar with CloudFront and this is not an issue related to fetching static assets in our control.
here is what I see in the PHP log:
[05-Jan-2023 20:01:22] WARNING: [pool www] child 1245876 exited on signal 15 (SIGTERM) after 640.030867 seconds from start
[05-Jan-2023 20:01:22] NOTICE: [pool www] child 1246366 started
[05-Jan-2023 20:08:42] WARNING: [pool www] child 1246366, script '/home/forge/XXXXXXXXXXXX.com/public/index.php' (request: "POST /index.php") execution timed out (68.131341 sec), terminating
here is what I'm seeing in the nginx log:
2023/01/05 20:08:34 [error] 1090486#1090486: *7599 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 98.171.XXX.XXX, server: XXXXXXXXXX.com, request: "POST /metrc_add_multiple_plants_to_harvest_save HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock", host: "XXXXXXXX.com", referrer: https://XXXXXXXXX.com/sync_planttags_with_these_weight_records/CCL20-0002559/KingstonLLC/2022-12-30/Compost%20Pile/KGF-2559-123022-CP-WST/KFarms-0001/125.2200/2/Lb/Cheetah/402/1A40603000256E1000000004/8...9
Has anyone else ever experienced this scenario and if so how did you solve it?
in reading https://mamchenkov.net/wordpress/2016/08/04/504-gateway-timeout-error-on-nginx-fastcgi-php-fpm/#:~:text=%E2%80%9C504%20Gateway%20Timeout%E2%80%9D%20error%20is,was%20willing%20to%20wait%20for. they reference updating fastcgi parameters but I've not tried this yet.
here is the fix:
in the Forge UI I updated the Max Execution Timeout (found on the PHP tab of the server).I also set therequest_terminate_timeout value in the PHP FPM at a higher value than the Max Execution Timeout
Please or to participate in this conversation.