Michdd Posted October 7, 2009 Share Posted October 7, 2009 I have a shell script using PHP. I would like to do something every X amount of seconds. The only solution that I can think of is putting something within my main (inf) loop to check and see if it has been the amount of time, if so do whatever. This doesn't seem like it would be the best method, but I can't think of anything else. Would this be okay to do? Or is there a better way? Quote Link to comment https://forums.phpfreaks.com/topic/176872-timer/ Share on other sites More sharing options...
mikesta707 Posted October 7, 2009 Share Posted October 7, 2009 have you considered a cron job? Quote Link to comment https://forums.phpfreaks.com/topic/176872-timer/#findComment-932592 Share on other sites More sharing options...
Michdd Posted October 7, 2009 Author Share Posted October 7, 2009 Of course, but I don't think that would be best for my situation. This shell script is acting as a server, and the operation that I want it to preform periodically has something to do with the data on the server. I suppose I could use a CRON and connect to my server through the php file run and have my server return the information back to the php file being called by CRON. But that seems unnecessary. Quote Link to comment https://forums.phpfreaks.com/topic/176872-timer/#findComment-932594 Share on other sites More sharing options...
thebadbad Posted October 7, 2009 Share Posted October 7, 2009 So have you considered using sleep() within your loop? Quote Link to comment https://forums.phpfreaks.com/topic/176872-timer/#findComment-932598 Share on other sites More sharing options...
Michdd Posted October 7, 2009 Author Share Posted October 7, 2009 I think you're understanding wrong. I can't use sleep(), because that would halt execution of the shell script.. I need the script to constant run to handle incoming packets and such. I just also want to run something every say... 5 minutes. I know I could do something like this: while(true) { if($last_update + 60*5 <= time()) { //It has been 5 minutes, } //Everything else.. } Is there a better way? Quote Link to comment https://forums.phpfreaks.com/topic/176872-timer/#findComment-932603 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.