| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: timers.php,v 1.1 2008/09/25 06:45:42 t0talmeltd0wn Exp $ |
| 3 |
|
|
| 4 |
|
$_xmpp_server_timers = array(); |
| 5 |
|
|
| 6 |
function _xmpp_server_run_timers() { |
function _xmpp_server_run_timers() { |
| 7 |
|
global $_xmpp_server_timers; |
| 8 |
|
foreach ($_xmpp_server_timers as $id => $timer) { |
| 9 |
|
if (time() > $timer['next']) { |
| 10 |
|
if (function_exists($timer['func'])) { |
| 11 |
|
$ret = call_user_func_array($timer['func'], $timer['args']); |
| 12 |
|
if (is_numeric($ret)) { |
| 13 |
|
$timer['delay'] = $ret; |
| 14 |
|
} |
| 15 |
|
$timer['next'] += $timer['delay']; |
| 16 |
|
} |
| 17 |
|
else { |
| 18 |
|
xmpp_server_cancel_timer($id); |
| 19 |
|
} |
| 20 |
|
} |
| 21 |
|
} |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
function xmpp_server_new_timer($delay, $func, $args = array()) { |
| 25 |
|
static $id; |
| 26 |
|
global $_xmpp_server_timers; |
| 27 |
|
$id++; |
| 28 |
|
$_xmpp_server_timers[$id] = array( |
| 29 |
|
'delay' => $delay, |
| 30 |
|
'next' => time() + $delay, |
| 31 |
|
'func' => $func, |
| 32 |
|
'args' => $args, |
| 33 |
|
); |
| 34 |
|
return $id; |
| 35 |
} |
} |
| 36 |
|
|
| 37 |
|
function xmpp_server_cancel_timer($id) { |
| 38 |
|
global $_xmpp_server_timers; |
| 39 |
|
unset($_xmpp_server_timers[$id]); |
| 40 |
|
} |