Browse Source

fix duplicate EV_TIMER_ONCE id

Ares 6 years ago
parent
commit
844a4c4ffe
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Events/Swoole.php

+ 6 - 1
Events/Swoole.php

@@ -23,6 +23,8 @@ class Swoole implements EventInterface
 
     protected $_timerOnceMap = array();
 
+    protected $mapId = 0;
+
     protected $_fd = array();
 
     // milisecond
@@ -55,7 +57,10 @@ class Swoole implements EventInterface
             case self::EV_TIMER:
             case self::EV_TIMER_ONCE:
                 $method = self::EV_TIMER == $flag ? 'tick' : 'after';
-                $mapId = count($this->_timerOnceMap);
+                if ($this->mapId > PHP_INT_MAX) {
+                    $this->mapId = 0;
+                }
+                $mapId = $this->mapId++;
                 $timer_id = Timer::$method($fd * 1000,
                     function ($timer_id = null) use ($func, $args, $mapId) {
                         call_user_func_array($func, $args);