Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/176872-timer/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176872-timer/#findComment-932594
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/176872-timer/#findComment-932603
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.