/[drupal]/contributions/modules/xmpp_server/includes/timers.php
ViewVC logotype

Diff of /contributions/modules/xmpp_server/includes/timers.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Thu Sep 25 06:45:42 2008 UTC revision 1.2, Fri Sep 26 02:45:30 2008 UTC
# Line 1  Line 1 
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    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2