Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When trying to run a PHP script (CentOS, Apache, PHP 5.2), that may take a long time, it is apparently killed after 45 minutes.

PHP script is invoked from a web browser, and in certain situations, it will do a lot of work processing a POP3 mailbox and sending emails as part of an automated monitoring system.

Running the PHP script from the command line might be a better option, but I want to understand what is going on so far.

I ran a test script, and it appeared to finally give an internal server error (500?) after 45 minutes.

Where is this limit set and what is killing the script, if that is what is happening?

It's running on a shared host on

share|improve this question

I assume you already did set_time_limit(0) in PHP to turn off the PHP max execution time for that specific script?

If you haven't tried it- that's probably the answer - if you did try that - then keep reading...

Linux allows you to setup a max run time for user processes - Shared hosts usually do that as a failsafe to kill any scripts that hang (otherwise you might have to restart the server to kill them - at the very least a sysadmin has to do it manually)

I can't seem to find the info I saw before - I'm pretty sure it's an extension of this

Either way, you will have to find a way to speed up your script- Why does it take 45 mins to run? Can you break it into segments? - Waiting 45 minutes for a response by a web-server is not really usable (what if you hit refresh and ran your script multiple times - or a web-spider hits it and triggers it without you knowing... could the server be negatively affected?)

share|improve this answer
Those are all valid points. This is a script that somebody tried to set up, and generally, it runs quickly. But under certain situations, he found that it could go on for a long time. A better design would probably be to break it into chunks and processes it outside of the PHP script that is called by the web server. Something run by cron that looked to see if there was work to be done in the queue and then processing a chunks at a time. – MarkS Aug 31 '12 at 23:42

Hostgator has a maximum 30 second PHP script execution time.

Hostgator PHP.ini variables that cannot be changed

As for your script,if your script is shutdown and restarted, does the script start from where it left off? If so, CRON jobs might be a good idea for you

Hostgator Support - Cron Jobs

It seems that hostgator also does not allow CRON jobs to be run in shorter than 15 minute intervals.

Hope this helps!

share|improve this answer
Very helpful. I agree that a process kicked off by cron that processed chunks of work would be helpful and a better design. – MarkS Aug 31 '12 at 23:45

This is what Hostgator support came back with:

On our shared servers, we do have automated monitoring systems that will interrupt processes based on certain resource usage to promote a stable environment. One of the limits we have in place is, as you have discovered, a 45-minute maximum run time for any user process. We can confirm that if you were to run this script in a shell or via the php exec(), etc, it would still be killed after 45 minutes.

You can get around this limitation by executing the script outside of our shared environment, for instance on a VPS or dedicated server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.