I have a function that is supposed to be an infinite function, but when I start it it keeps loading. in this case he keeps going around 70-79 seconds while I have specified 21 in set_time_limit.
When I start it doesn’t do anything and when those 75 seconds are done it suddenly display 8 times the date difference. all at once. I want it to display my text every 1 second and without lagging for 1 hour long
all my values below are lower then the numbers I said above because I thought that 1 second would maybe to fast but it still lags for 10 seconds
set_time_limit (21);
// 21 seconds until its done should become an hour later
// this was to test
$x=1;
$startTime = time();
$timeout = 10; //timeout in seconds
for ($i=0;;$i++)
{
if(time() > $startTime + ($x * $timeout)) {
$x++;
$today=date('d-m-Y H:i:s');
echo "it's now: ". $today . "</br>";
$newyear = date('d-m-Y H:i:s', mktime(0, 0, 0, 01, 01, 2013));
$difference=get_datediff_string($vandaag,$nieuwjaar);
// get_datediff_string() is defined somewhere below,
// but wasn't worth to show it.
echo "it is $difference untill newyear";
}
}
This is caused by implicit buffering. It might be on the server side (in which case just calling
flush()afterechoshould fix it), or it might be on the browser (in which case you’re out of luck).This kind of script really should be a console program anyway, I really don’t see the point of what you’re doing in a browser context.