This is a discussion on Sleep Function within the PHP General forums, part of the PHP Programming Forums category; The php.net documentation for the sleep and usleep functions has me confused. I'm using shared hosting and I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
The php.net documentation for the sleep and usleep functions has me
confused. I'm using shared hosting and I need to email my whole mailing list while not clogging the shared mail server. What I'm trying to do is put a pause between each email sent (like 10 seconds) so I can set it up to send a thousand (or whatever) messages without manually putting time between batches. My guess is that I should put a line with sleep(10); inside the mail sending loop so that it pauses between notes. However, the Jan-17 note on the usleep function mentions that these kinds of loops can consume 100% of CPU while running. The Jan-29 note on the time() function says that sleep uses way less CPU than wait(). I don't know how to test CPU usage of any PHP function. Is sleep() really so CPU intensive that I should avoid it, is there a better function to use, or is it exactly what I need and it'll be no problem even on a shared server? Thanks! Glenn Gasner glenn at perex dot com |
|
|||
|
It is exactly what you need. And you can lower the sleep time, I think 1
or 2 seconds are just enough. Glenn Gasner wrote: > The php.net documentation for the sleep and usleep functions has me > confused. I'm using shared hosting and I need to email my whole mailing > list while not clogging the shared mail server. What I'm trying to do is > put a pause between each email sent (like 10 seconds) so I can set it up to > send a thousand (or whatever) messages without manually putting time between > batches. My guess is that I should put a line with sleep(10); inside the > mail sending loop so that it pauses between notes. However, the Jan-17 note > on the usleep function mentions that these kinds of loops can consume 100% > of CPU while running. The Jan-29 note on the time() function says that > sleep uses way less CPU than wait(). I don't know how to test CPU usage of > any PHP function. Is sleep() really so CPU intensive that I should avoid > it, is there a better function to use, or is it exactly what I need and > it'll be no problem even on a shared server? > > Thanks! > Glenn Gasner > glenn at perex dot com > |