Max_execution_time is 30 but my script runs longer

Locally I’m using XAMPP and I have max_execution_time set to 30. My PHP script runs for 30 minutes and it executes fine.

When I try the same script on shared hosting which has max_execution_time = 30, I get 504 error in browser.

I don’t understand why this happens? It has to be with some server configuration, but I don’t know what exactly.

How are you running the script?

Via browser, GUI

Have you restarted the server since you set max_execution_time to 30?

That’s the problem. Locally (XAMPP) it works fine and yes it is restarted, on shared hosting I get 504

and the script itself isnt setting an execution timeout?

That’s right, it doesn’t. That’s why I don’t understand

Let me quess.

https://www.php.net/manual/en/info.configuration.php#ini.max-execution-time

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

i.e. if you check. the value is lower than the default.

What are you doing that takes 30 minutes to run by Php?

I missed the jump to minutes from seconds. :see_no_evil:

I can’t imagine any shared host wanting one site’s script to negatively impact other customers sharing the server.

On the other hand, I have no problem with one abusing ones own [localhost] server. Run sloppy code, push PHP to its limits, wait hours for a job, be willing to have all resources consumed by the script, accept the risk of potentially causing major problems … - if you want. PHP code doesn’t shoot devs in the foot.

I have been annoyed at times with default values that didn’t suit my needs. BUT, I have learned that they are what they are for reason and I best think about why they are what they are and why I want to change them. I would guess that for the most extreme changes from defaults, most if not all were not because of any PHP limitations but because of inefficiencies. eg. poorly designed database architecture, poorly written queries, and yes, a good helping of poorly written newbie code along the way.

The point is, look for alternate approaches and tweak time limits (and memory limits) as a last resort.

3 Likes