I used a log printer to test to see if the ignore_user_abort works, it does. However the echo does not want to work. Will an echo only work when a loop compleates?
<?php
ignore_user_abort(1); // run script in background
set_time_limit(0); // run script forever
$interval=2; // do every 2 sec...
$i=0;
$lastRunLog = 'lastrun.log';
do{
// add the script that has to be ran every 2 sec here
// ...
echo 'Test: '.$i;
file_put_contents($lastRunLog, time());
sleep($interval); // wait 2 sec
$i=$i+1;
}while(true);
?>
Yes, and no.
There are three output buffers you need to worry about:
So, echo puts into the PHP buffer immediately. You can send the buffer to teh webserver, but after that it's out of your hands.