Is it possible to PHP display any loop with time interval For example: - I like to display 1 after 5 minutes, the display will show 2. Any help would be great. Thank you in advance.
PHP
Sample Cron Job
#!/usr/bin/env php <?php # This file would be say, '/usr/local/bin/run.php' // code echo "this was run from CRON"
Then add an entry to your crontab:
* * * * * /usr/bin/php -f /usr/local/bin/run.php &> /dev/null
Source: fooobar.com/questions/85331 / ...
If you need it for a long time, by running php script (loop), you can use time () to get the start time of each interval.
$start = time(); $cnt = 0; while (1) # your loop { $now = time(); if($start +(5*60)>=$now) { $start = $now; $cnt++; echo $cnt; } }
foreach (range(1, 10) as $number) { echo $number; sleep(60); }
here
Maybe combine it with flush () to test it.
if (ob_get_level() == 0) ob_start(); for ($i = 0; $i<10; $i++){ echo "<br> Line to show."; echo str_pad('',4096)."\n"; ob_flush(); flush(); sleep(2); } echo "Done."; ob_end_flush(); ?>