Page 1 of 1
why do I need to make my Script sleep?
Posted: Tue Sep 11, 2007 11:36 am
by kelmadics
Just curious why is it sometimes necessary to make a code sleep() specially if
the code is long running script? I know its a dumb q but your knowledge would help
Thanks
Posted: Tue Sep 11, 2007 12:58 pm
by kaszu
Last time i used it to check if image caching was working properly in IE6.
Getting image from server (localhost) was very fast, so i needed something to slow it down to see if they were from cache or from server, so i just returned image to browser after sleep().
Posted: Tue Sep 11, 2007 1:54 pm
by kelmadics
what i was actually wondering is how to make memory more efficient while running a script. Lets say i am sending an eblast with 100000 emails
if i query those emails using mysql_fetch_array, those emails will be stored in memory. what i wanted to do is dump the emails that has already run thrugh the script. So let say ive sent the first 100 emails of the 100000 i want to dump those 100 in the array memory because its useless. Mistakenly I was thinking that the sleep commands "refreshes" the memory of the script. please correct me.
Posted: Tue Sep 11, 2007 2:17 pm
by feyd
sleep() does little as far as memory is concerned. It is used to prevent your script from inhaling the server's processor(s), nothing more.
If these emails are sent per record you aren't sucking up major amounts of memory as far as PHP is concerned provided you don't have PHP store more than a record. Generally there's little reason to store more than the current record if you're sending customized emails.
Posted: Tue Sep 11, 2007 3:06 pm
by volka
feyd wrote:If these emails are sent per record you aren't sucking up major amounts of memory as far as PHP is concerned provided you don't have PHP store more than a record.
Which means that you should use an unbuffered query, like
mysql_unbuffered_query() or
PDO
You might want to consider something like
majordomo instead of a selfmade php script for your non-spam opt in/out mailing list
Posted: Tue Sep 11, 2007 4:53 pm
by s.dot
sleep() is important in infinite loops to delay the script and prevent it from using up all available memory.
Posted: Tue Sep 11, 2007 5:32 pm
by mrkite
scottayy wrote:sleep() is important in infinite loops to delay the script and prevent it from using up all available memory.
I thought gc would run regardless. sleep() would prevent cpu hogging.