PHP script stops running arbitrarily with no errors


Solution 1

I appreciate everyone's comments. Especially James Hartig's, you were very helpful and sent me on the right path. I still don't know what the problem was. I got it to run on the server with using SSH, just by using the exec() command as well as the ignore_user_abort(). But it would still time out. So, I just had to break it into small pieces that will run for only about 2 minutes each, and use session variables/arrays to store where I left off. I'm glad to be done with this fairly simple project now, and am supremely pissed at 1and1. Oh well...

Solution 2

At some point your browser times out and stops loading the page. If you want to test, open up the command line and run the code in there. The script should run indefinitely.

Solution 3

Have you considered just running the script from the command line, eg:

php script.php

and have the script flush out a message every so often that its still running:


while (true) {
  echo "still alive...";

Solution 4

in such cases, i turn on all the development settings in php.ini, of course on a development server. This display many more messages, including deprecation warnings.

In my experience of debugging long running php scripts, the most common cause was memory allocation failure (Fatal error: Allowed memory size of xxxx bytes exhausted...)

Solution 5

I think what you need to find out is the exact time that it stops (you can set an initial time and keep dumping out the current time minus initial). There is something on the server side that is stopping the file. Also, consider doing an ini_get to check to make sure the execution time is actually 0. If you want, set the time limit to 30 and then EVERY loop you make, continue setting at 30. Every time you call set_time_limit, the counter resets and this might allow you to bypass the actual limits. If this still isn't working, there is something on 1and1's servers that might kill the script.

Also, did you try the ignore_user_abort?

Author by


Updated on June 12, 2022


  • RobHardgood
    RobHardgood 3 months

    I have a PHP script that seemed to stop running after about 20 minutes.

    To try to figure out why, I made a very simple script to see how long it would run without any complex code to confuse me.

    I found that the same thing was happening with this simple infinite loop. At some point between 15 and 25 minutes of running, it stops without any message or error. The browser says "Done".

    I've been over every single possible thing I could think of:

    set_time_limit ( session.gc_maxlifetime in the php.ini)

    The point that the script is stopped is not consistent. Sometimes it will stop at 15 minutes, sometimes 22 minutes.

    Please, any help would be greatly appreciated.

    It is hosted on a 1and1 server. I contacted them and they don't provide support for bugs caused by developers.