B4NZ41 B4NZ41 - 15 days ago 5
PHP Question

Sleep function on php

As a possible alternative to using cron jobs, I found the sleep function. I have never used this before.

If I tell my script to run inside a kind of loop, and inside that loop I have an instruction like this

# sleeps for 86400 seconds or one day
sleep(86400);


will my script be launched again after 1 day? even if don't access it on my web browser again within that period?
I think is not possible, but I'm here to ask an expert about it.

aib aib
Answer

The main problem with using PHP this way is, in my experience, not web server timeouts (there are ways to handle that with difficulty varying on the server and the platform) but memory leaks.

Straightforward PHP code tends to leak a lot of memory; most of the scripts I wrote were able to do hundreds of times as many work after I did some analysis and placed some unsets. And I was never able to prevent all the leaks this way. I'm also told there are memory leaks in the standard library, which, if true, makes it impossible to write daemons that would run for a long time in loops.

Comments