X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=blobdiff_plain;f=Tools%2Ftimer.inc.php;fp=Tools%2Ftimer.inc.php;h=1ba5cd7488f9e14b9158e4ab2375c77d3139d860;hp=445ab671621a335b1058003639336104e96bced8;hb=7f51193ddac01b0540000c756c50167ff015e02a;hpb=811bc0c7a1f583fb624a0f8c3601146e063c5a25 diff --git a/Tools/timer.inc.php b/Tools/timer.inc.php index 445ab67..1ba5cd7 100644 --- a/Tools/timer.inc.php +++ b/Tools/timer.inc.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * - * * + * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Tools/timer.inc.php * * timer functions @@ -24,50 +24,53 @@ $timers['id']=0; function timer_loop() { - global $timers; - $mtime = microtime(true); - $ret = false; - foreach ($timers as $id => $timer) { - if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs) - if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) { - call_user_func_array($timer['function'],$timer['params']); - } - $ret = true; - unset($timers[$id]); - } - } - return $ret; + global $timers; + $mtime = microtime(true); + $ret = false; + foreach ($timers as $id => $timer) { + if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs) + if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) { + call_user_func_array($timer['function'],$timer['params']); + } + $ret = true; + unset($timers[$id]); + } + } + return $ret; } function timer($seconds,$command,$parameter) { - global $timers; - $new['expire'] = microtime(true) + $seconds; - $new['function'] = $command; - $new['params'] = $parameter; - while(isset($timers[$timers['id']])|| !isset($timers['id'])) { - $timers['id']++; - if($timers['id'] > 9999999) $timers['id'] = 0; - } - $timers[$timers['id']] = $new; - return $timers['id']; + global $timers; + $new['expire'] = microtime(true) + $seconds; + $new['function'] = $command; + $new['params'] = $parameter; + if(!array_key_exists('id', $timers)) { + $timers['id'] = 0; + } + while(isset($timers[$timers['id']])|| !isset($timers['id'])) { + $timers['id']++; + if($timers['id'] > 9999999) $timers['id'] = 0; + } + $timers[$timers['id']] = $new; + return $timers['id']; } function utimer($seconds,$command,$parameter) { - global $timers; - $new['expire'] = microtime(true) + ($seconds / 1000); - $new['function'] = $command; - $new['params'] = $parameter; - while($timers[$timers['id']] || !$timers['id']) { - $timers['id']++; - if($timers['id'] > 9999999) $timers['id'] = 0; - } - $timers[$timers['id']] = $new; - return $timers['id']; + global $timers; + $new['expire'] = microtime(true) + ($seconds / 1000); + $new['function'] = $command; + $new['params'] = $parameter; + while($timers[$timers['id']] || !$timers['id']) { + $timers['id']++; + if($timers['id'] > 9999999) $timers['id'] = 0; + } + $timers[$timers['id']] = $new; + return $timers['id']; } function kill_timer($id) { - global $timers; - unset($timers[$id]); + global $timers; + unset($timers[$id]); } $timers['id']=0;