note 92659 added to function.microtime

From: Date: Sun, 02 Aug 2009 23:23:33 +0000
Subject: note 92659 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-159019@lists.php.net to get a copy of this message
Want to make sure your script doesn't time out on large updates? Say you're doing a poor mans cron job or working with large amounts of data in loop and the user begins to hang too long. Instead of them giving up and leaving you can break the loop when it reaches a set time and still display data. Here's a simple handy dandy loop timer rounded to second. <?php $starttime = round(microtime(true)); $totaltime = 0; $maxtime = 5; //seconds for ($i = 1; $i <= 20; $i++) { /// 20 loops 1 sec each usleep(1000000); if($totaltime < $maxtime){ $currenttime = round(microtime(true)); $totaltime = $totaltime + ($currenttime -$starttime); //update and continue echo $i.'<br>'; }else{ // stop updating or display not updated data. break; } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 75.173.173.128 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/92659 Del: integrated -- https://master.php.net/note/delete/92659/integrated Del: useless -- https://master.php.net/note/delete/92659/useless Del: bad code -- https://master.php.net/note/delete/92659/bad+code Del: spam -- https://master.php.net/note/delete/92659/spam Del: non-english -- https://master.php.net/note/delete/92659/non-english Del: in docs -- https://master.php.net/note/delete/92659/in+docs Del: other reasons-- https://master.php.net/note/delete/92659 Reject -- https://master.php.net/note/reject/92659 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159019) next »