Execute script at intervals in php

Meryvn picture Meryvn · Feb 20, 2013 · Viewed 7.8k times · Source

i would like to execute a script every 2 minutes until i close the window.My script am executing every 2 minutes writes to a file. My script is not writing to the file. please see my interval script.

<?php
$interval = 1; //minutes
set_time_limit (0);
while (true)
{
  $now=time ();
  echo $now . "<BR>";
  sleep ($interval * 1 - (time () - $now));
}
?>

Answer

Dipesh Parmar picture Dipesh Parmar · Feb 20, 2013

Try

<?php
function do_stuff(){

  // do something

 sleep(20); // wait 20 seconds
 do_stuff(); // call this function again
}
?>