mkoga Posted March 29, 2008 Share Posted March 29, 2008 I'm planning on sending some emails 10 seconds apart from each other until an email queue is complete. Does anyone have an opinion on which would be better for performance? I could sleep(10) after each email sent or run a cron job every 10 seconds. I would rather use a cron job, but I would have to keep the cron job running every 10 seconds 24/7 unless I did an exec('crontab') call. I guess what it basically comes down to is which is better: running one really long php instance or running a bunch of really short php instances? Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/ Share on other sites More sharing options...
mkoga Posted March 29, 2008 Author Share Posted March 29, 2008 Bump Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504133 Share on other sites More sharing options...
Northern Flame Posted March 29, 2008 Share Posted March 29, 2008 you could run a cron job that has the sleep function in it Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504142 Share on other sites More sharing options...
mkoga Posted March 29, 2008 Author Share Posted March 29, 2008 you could run a cron job that has the sleep function in it wouldn't that defeat the purpose of a cron job? Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504146 Share on other sites More sharing options...
Northern Flame Posted March 29, 2008 Share Posted March 29, 2008 well i mean if you want the emails sent every 10 seconds and you dont want to run a different cron job every 10 seconds, you could run one cron job that will send the emails every 10 seconds Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504149 Share on other sites More sharing options...
moon 111 Posted March 29, 2008 Share Posted March 29, 2008 I would definitely use a cron job. well i mean if you want the emails sent every 10 seconds and you dont want to run a different cron job every 10 seconds, you could run one cron job that will send the emails every 10 seconds The whole point of a cron job is running code repeatedly. If hes running one long script why would he need the cron job? He only needs to run it once! Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504152 Share on other sites More sharing options...
BlueSkyIS Posted March 29, 2008 Share Posted March 29, 2008 does crontab provide timing of events down to seconds? I thought it only went to minutes. Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504160 Share on other sites More sharing options...
cooldude832 Posted March 29, 2008 Share Posted March 29, 2008 better idea is to do this Make a cron run once every hour or half hour so you aren't over running the server In the cron it looks like <?php #Get the time right now $time #Get the list of emails to be sent indexed from 0-n $i = 0; #Also get $in_time initalized while($time < "Time + 59 mins 30 seconds" && EMAILS TO BE SENT){ #Check to make sure at iteration didn't take less than 10 seconds if(GET_TIME_NOW-$in_time <10{ sleep(GET_TIME_NOW_$in_time); } #now we have waited at least 10 seconds lets send email #send emails from $i-How many per 10 second period making sure $i++; for each mail sent #Get the time again to $in_time for the top par of the loop } ?> Basic Idea that probably is better since the cron only refreshes on a minute scale vs a second scale you won't be calling as many dead sets. Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504161 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 Erm.. well a cron is run from the server and a sleep would be via a user script.. it all depends on when you want it to run! and what is for! Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504164 Share on other sites More sharing options...
mkoga Posted March 29, 2008 Author Share Posted March 29, 2008 Erm.. well a cron is run from the server and a sleep would be via a user script.. it all depends on when you want it to run! and what is for! sure, but the cron would just in turn execute a php script. so i'm thinking have a cron run once a day to execute this little email queue. the email queue would then iterate through each email that needs to be sent, sleep(10) then goes on to the next email. when the queue is complete, the script ends. Quote Link to comment https://forums.phpfreaks.com/topic/98442-sleep-vs-cron-job/#findComment-504177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.