PHP script stops working randomly without errors

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

To find out why, I made a very simple script to see how long it would work without any complicated code to confuse me.

I found that the same thing happens with this simple infinite loop. At some point between 15 and 25 minutes of work, he stops without any messages or errors. The browser says "Finish."

I survived every possible thing that I could think of:

set_time_limit ( session.gc_maxlifetime in the php.ini) memory_limit max_execution_time 

The script breakpoint is incompatible. Sometimes it stops for 15 minutes, sometimes for 22 minutes.

Please any help would be greatly appreciated.

It is hosted on server 1and1 . I contacted them and they do not support errors caused by developers.

+7
scripting php while-loop
source share
6 answers

I appreciate all the comments. Especially James Hartig, you were very helpful and sent me on the right track. I still don’t know what the problem is. I got it to run on the server using SSH, just using the exec () command, as well as ignore_user_abort (). But still there will be time. So I just had to break it into small pieces, which would only work for about 2 minutes each, and use session variables / arrays to store where I left off. I'm glad I ended this fairly simple project and was extremely pissed at 1 and 1. Oh, well ...

0
source share

At some point, your browser shuts down and stops loading the page. If you want to test, open a command prompt and run the code there. The script should work unlimited.

+3
source share

Have you considered just running a script from the command line, for example:

 PHP .php 

and the script displays the message so often that it still works:

 <?php while (true) { doWork(); echo "still alive..."; flush(); } 
+3
source share

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

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

+2
source share

I think that you need to find out the exact time it stopped (you can set the start time and leave to reset the current time minus the start). On the server side there is something that stops the file. Also consider doing an ini_get to make sure that the runtime is actually 0. If you want, set a time limit of 30, and then the EVERY loop that you do, continue to set to 30. Each time you call set_time_limit, the counter resets and this may allow you to bypass the actual limits. If this still doesn't work, there is something on servers 1 and 1 that could kill the script.

Also have you tried ignore_user_abort?

+1
source share

I think this is because some process monitor kills the "zombie processes" in order to provide resources to other users.

Run exec with "2> & 1" to write everything, including stderr.

In my release, I managed to catch this:

 ... script.sh: line 4: 15932 Killed php5-cli -d max_execution_time=0 -d memory_limit=128M myscript.php 

So something (external power, not PHP itself) is killing my process!

I use IdWebSpace , which is a great BTW, but I think most hosting providers impose this resource / process management mechanism just to be normal.

0
source share

All Articles