Browse Source

Merge pull request #2 from walkor/master

update from master
sukui 9 years ago
parent
commit
cdcf7bfb9e
5 changed files with 14 additions and 25 deletions
  1. 1 11
      Events/Event.php
  2. 7 8
      Events/Select.php
  3. 1 1
      Protocols/Http.php
  4. 1 1
      README.md
  5. 4 4
      Worker.php

+ 1 - 11
Events/Event.php

@@ -86,19 +86,9 @@ class Event implements EventInterface
                 return self::$_timerId++;
                 return self::$_timerId++;
                 
                 
             default :
             default :
-
-                $callback = function ($fd) use ($func) {
-                    try {
-                        call_user_func($func, $fd);
-                    } catch (\Exception $e) {
-                        echo $e;
-                        exit(250);
-                    }
-                };
-
                 $fd_key = (int)$fd;
                 $fd_key = (int)$fd;
                 $real_flag = $flag === self::EV_READ ? \Event::READ | \Event::PERSIST : \Event::WRITE | \Event::PERSIST;
                 $real_flag = $flag === self::EV_READ ? \Event::READ | \Event::PERSIST : \Event::WRITE | \Event::PERSIST;
-                $event = new \Event($this->_eventBase, $fd, $real_flag, $callback);
+                $event = new \Event($this->_eventBase, $fd, $real_flag, $func, $fd);
                 if (!$event||!$event->add()) {
                 if (!$event||!$event->add()) {
                     return false;
                     return false;
                 }
                 }

+ 7 - 8
Events/Select.php

@@ -181,11 +181,12 @@ class Select implements EventInterface
     protected function tick()
     protected function tick()
     {
     {
         while (!$this->_scheduler->isEmpty()) {
         while (!$this->_scheduler->isEmpty()) {
-            $scheduler_data = $this->_scheduler->top();
-            $timer_id       = $scheduler_data['data'];
-            $next_run_time  = -$scheduler_data['priority'];
-            $time_now       = microtime(true);
-            if ($time_now >= $next_run_time) {
+            $scheduler_data       = $this->_scheduler->top();
+            $timer_id             = $scheduler_data['data'];
+            $next_run_time        = -$scheduler_data['priority'];
+            $time_now             = microtime(true);
+            $this->_selectTimeout = ($next_run_time - $time_now) * 1000000;
+            if ($this->_selectTimeout <= 0) {
                 $this->_scheduler->extract();
                 $this->_scheduler->extract();
 
 
                 if (!isset($this->_task[$timer_id])) {
                 if (!isset($this->_task[$timer_id])) {
@@ -203,10 +204,8 @@ class Select implements EventInterface
                     $this->del($timer_id, self::EV_TIMER_ONCE);
                     $this->del($timer_id, self::EV_TIMER_ONCE);
                 }
                 }
                 continue;
                 continue;
-            } else {
-                $this->_selectTimeout = ($next_run_time - $time_now) * 1000000;
-                return;
             }
             }
+            return;
         }
         }
         $this->_selectTimeout = 100000000;
         $this->_selectTimeout = 100000000;
     }
     }

+ 1 - 1
Protocols/Http.php

@@ -42,7 +42,7 @@ class Http
         if (0 === strpos($recv_buffer, "POST")) {
         if (0 === strpos($recv_buffer, "POST")) {
             // find Content-Length
             // find Content-Length
             $match = array();
             $match = array();
-            if (preg_match("/\r\nContent-Length: ?(\d+)/", $header, $match)) {
+            if (preg_match("/\r\nContent-Length: ?(\d+)/i", $header, $match)) {
                 $content_length = $match[1];
                 $content_length = $match[1];
                 return $content_length + strlen($header) + 4;
                 return $content_length + strlen($header) + 4;
             } else {
             } else {

+ 1 - 1
README.md

@@ -258,7 +258,7 @@ $worker = new Worker('tcp://0.0.0.0:1234');
 $worker->count=3;
 $worker->count=3;
 $worker->onMessage = function($connection, $data)
 $worker->onMessage = function($connection, $data)
 {
 {
-    $connection->send("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nServer: workerman\1.1.4\r\n\r\nhello");
+    $connection->send("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nServer: workerman\r\nContent-Length: 5\r\n\r\nhello");
 };
 };
 Worker::runAll();
 Worker::runAll();
 ```
 ```

+ 4 - 4
Worker.php

@@ -508,7 +508,7 @@ class Worker
                 $worker->user = self::getCurrentUser();
                 $worker->user = self::getCurrentUser();
             } else {
             } else {
                 if (posix_getuid() !== 0 && $worker->user != self::getCurrentUser()) {
                 if (posix_getuid() !== 0 && $worker->user != self::getCurrentUser()) {
-                    self::log('Waring: You must have the root privileges to change uid and gid.');
+                    self::log('Warning: You must have the root privileges to change uid and gid.');
                 }
                 }
             }
             }
 
 
@@ -927,7 +927,7 @@ class Worker
         // Get uid.
         // Get uid.
         $user_info = posix_getpwnam($this->user);
         $user_info = posix_getpwnam($this->user);
         if (!$user_info) {
         if (!$user_info) {
-            self::log("Waring: User {$this->user} not exsits");
+            self::log("Warning: User {$this->user} not exsits");
             return;
             return;
         }
         }
         $uid = $user_info['uid'];
         $uid = $user_info['uid'];
@@ -935,7 +935,7 @@ class Worker
         if ($this->group) {
         if ($this->group) {
             $group_info = posix_getgrnam($this->group);
             $group_info = posix_getgrnam($this->group);
             if (!$group_info) {
             if (!$group_info) {
-                self::log("Waring: Group {$this->group} not exsits");
+                self::log("Warning: Group {$this->group} not exsits");
                 return;
                 return;
             }
             }
             $gid = $group_info['gid'];
             $gid = $group_info['gid'];
@@ -946,7 +946,7 @@ class Worker
         // Set uid and gid.
         // Set uid and gid.
         if ($uid != posix_getuid() || $gid != posix_getgid()) {
         if ($uid != posix_getuid() || $gid != posix_getgid()) {
             if (!posix_setgid($gid) || !posix_initgroups($user_info['name'], $gid) || !posix_setuid($uid)) {
             if (!posix_setgid($gid) || !posix_initgroups($user_info['name'], $gid) || !posix_setuid($uid)) {
-                self::log("Waring: change gid or uid fail.");
+                self::log("Warning: change gid or uid fail.");
             }
             }
         }
         }
     }
     }