AlexandreBillereau's avatar

Long-running POST API route stops after ~30 seconds despite increasing max_execution_time

Hi all,

We have a POST route in routes/api.php for creating a temporary landing page:

Route::post('/create-landing-page', [TempLandingPageController::class, 'function_with_anonyme_name']);

The issue is that when the script runs longer than ~30 seconds, it just stops, even though we’ve tried increasing the execution time at runtime:

$init_set_string = ini_set('max_execution_time', 700);

We’ve checked all the usual places (php.ini, .user.ini, .htaccess, etc.), and everything reports 120 seconds, but the request still dies at ~30 seconds.

Additionally, when we try to hit the route via GET (by mistake), we get:

The GET method is not supported for route api/function_with_anonyme_name. Supported methods: POST.

Details we know:

PHP CLI is fine (max_execution_time = 0), so scripts run fine in Tinker or CLI.

The server is Apache + PHP-FPM under cPanel, multiple PHP versions installed.

The POST route is executed through the web, so FPM / Apache timeouts may be involved.

All our .ini changes (php.ini, user.ini, .htaccess) don’t seem to affect this 30s limit.

Memory and file size limits are set high enough.

We suspect some server-level timeout (Apache / FPM / proxy) is cutting the request early, but we’re not sure exactly where or how to override it safely for this API route.

Any ideas on what could cause a POST route to stop at 30s despite max_execution_time being increased, and how to fix it for long-running processes?

Thanks in advance.

0 likes
3 replies
Glukinho's avatar

Have you checked Apache logs and php-fpm logs?

Is it always exactly 30 seconds or timeout differs from time to time?

If you place simple sleep(10000); in the controller and fire a request, will execution break the same way after same time? Or behaviour is different?

Additionally, when we try to hit the route via GET (by mistake), we get:

The GET method is not supported for route api/function_with_anonyme_name. Supported methods: POST.

This has nothing to do with the problem, you just didn't define GET route.

Tray2's avatar

Is this some kind of huge upload of some kind, or is it the processing of something that takes time?

If it is processing and you can't speed it up, you should consider using a background job for it, and release the user request asap, and inform the user when whatever it ism is available.

Snapey's avatar

The browser probably gives up, and I can't say I blame it.

I expect the solution to be move whatever humungous task you are doing into a job.

Please or to participate in this conversation.