2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
26 function timer_loop() {
28 $mtime = microtime(true);
30 foreach ($timers as $id => $timer) {
31 if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs)
32 if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) {
33 call_user_func_array($timer['function'],$timer['params']);
42 function timer($seconds,$command,$parameter) {
44 $new['expire'] = microtime(true) + $seconds;
45 $new['function'] = $command;
46 $new['params'] = $parameter;
47 while(isset($timers[$timers['id']])|| !isset($timers['id'])) {
49 if($timers['id'] > 9999999) $timers['id'] = 0;
51 $timers[$timers['id']] = $new;
55 function utimer($seconds,$command,$parameter) {
57 $new['expire'] = microtime(true) + ($seconds / 1000);
58 $new['function'] = $command;
59 $new['params'] = $parameter;
60 while($timers[$timers['id']] || !$timers['id']) {
62 if($timers['id'] > 9999999) $timers['id'] = 0;
64 $timers[$timers['id']] = $new;
68 function kill_timer($id) {