-6

I have a while loop which will run forever as I need. Now I want to run scheduler in that loop and I want to run some command after every hour in that loop. Is this possible ? Current code . I dont want to use sleep since I want to continuously check for other codes so don't suggest SLEEP ,JAVASCRIPT & CONJOBS

<?php
set_timelimit(0);

while(true)
{
  getChat();

 //Here I want to run a function after every hour. How do I do it ?
 if(everyhour)
 {
      runthisfunction()
 }


}
Cœur
  • 37,241
  • 25
  • 195
  • 267
JohnJexon
  • 3
  • 3

2 Answers2

3

You can use a Cron job to call a PHP script at certain intervals.

OR

Try scheduled tasks through CronJobs.

Also have a look through this article to run PHP scripts through Cron.

So basically what you will have to do is create the script you want to run via PHP and using the above articles create a Cron for the specific interval.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • 1
    this is gonna get downvotes ... just a heads up .. since he specifically mentions cronjobs (regardless of it being the "right" answer) ... (or maybe not ... nice) – Joran Beasley Jan 06 '16 at 06:30
  • Already mentioned that I dont want to use cronjobs. Well, Rechard already gave the solution. – JohnJexon Jan 06 '16 at 06:37
3

You could probably do something like:

if(date('i') == '00'){
    //do code
}

Though you'll likely need to use something like flush() to get any output to show up.