walkor преди 10 години
родител
ревизия
9811859101
променени са 6 файла, в които са добавени 30 реда и са изтрити 30 реда
  1. 6 6
      Workerman/Connection/TcpConnection.php
  2. 2 2
      Workerman/Events/Libevent.php
  3. 1 1
      Workerman/Events/Select.php
  4. 6 6
      Workerman/Protocols/Http.php
  5. 4 4
      Workerman/WebServer.php
  6. 11 11
      Workerman/Worker.php

+ 6 - 6
Workerman/Connection/TcpConnection.php

@@ -210,7 +210,7 @@ class TcpConnection extends ConnectionInterface
             return null;
         }
         // 如果当前连接是关闭,则返回false
-        elseif($this->_status == self::STATUS_CLOSING || $this->_status == self::STATUS_CLOSED)
+        elseif($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED)
         {
             return false;
         }
@@ -349,7 +349,7 @@ class TcpConnection extends ConnectionInterface
      */
     public function resumeRecv()
     {
-        if($this->_isPaused == true)
+        if($this->_isPaused === true)
         {
             Worker::$globalEvent->add($this->_socket, EventInterface::EV_READ, array($this, 'baseRead'));
             $this->_isPaused = false;
@@ -430,7 +430,7 @@ class TcpConnection extends ConnectionInterface
                    // 数据足够一个包长
                    self::$statistics['total_request']++;
                    // 当前包长刚好等于buffer的长度
-                   if(strlen($this->_recvBuffer) == $this->_currentPackageLength)
+                   if(strlen($this->_recvBuffer) === $this->_currentPackageLength)
                    {
                        $one_request_buffer = $this->_recvBuffer;
                        $this->_recvBuffer = '';
@@ -497,7 +497,7 @@ class TcpConnection extends ConnectionInterface
                 }
             }
             // 如果连接状态为关闭,则销毁连接
-            if($this->_status == self::STATUS_CLOSING)
+            if($this->_status === self::STATUS_CLOSING)
             {
                 $this->destroy();
             }
@@ -534,7 +534,7 @@ class TcpConnection extends ConnectionInterface
      */
     public function close($data = null)
     {
-        if($this->_status == self::STATUS_CLOSING || $this->_status == self::STATUS_CLOSED)
+        if($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED)
         {
             return false;
         }
@@ -589,7 +589,7 @@ class TcpConnection extends ConnectionInterface
     public function destroy()
     {
         // 避免重复调用
-        if($this->_status == self::STATUS_CLOSED)
+        if($this->_status === self::STATUS_CLOSED)
         {
             return false;
         }

+ 2 - 2
Workerman/Events/Libevent.php

@@ -89,7 +89,7 @@ class Libevent implements EventInterface
                 
             default :
                 $fd_key = (int)$fd;
-                $real_flag = $flag == self::EV_READ ? EV_READ | EV_PERSIST : EV_WRITE | EV_PERSIST;
+                $real_flag = $flag === self::EV_READ ? EV_READ | EV_PERSIST : EV_WRITE | EV_PERSIST;
                 
                 $event = event_new();
                 
@@ -166,7 +166,7 @@ class Libevent implements EventInterface
     protected function timerCallback($_null, $_null, $timer_id)
     {
         // 如果是连续的定时任务,再把任务加进去
-        if($this->_eventTimer[$timer_id][3] == self::EV_TIMER)
+        if($this->_eventTimer[$timer_id][3] === self::EV_TIMER)
         {
             event_add($this->_eventTimer[$timer_id][2], $this->_eventTimer[$timer_id][4]);
         }

+ 1 - 1
Workerman/Events/Select.php

@@ -177,7 +177,7 @@ class Select implements EventInterface
                 // 任务数据[func, args, flag, timer_interval]
                 $task_data = $this->_task[$timer_id];
                 // 如果是持续的定时任务,再把任务加到定时队列
-                if($task_data[2] == self::EV_TIMER)
+                if($task_data[2] === self::EV_TIMER)
                 {
                     $next_run_time = $time_now+$task_data[3];
                     $this->_scheduler->insert($timer_id, -$next_run_time);

+ 6 - 6
Workerman/Protocols/Http.php

@@ -160,9 +160,9 @@ class Http
         }
         
         // 需要解析$_POST
-        if($_SERVER['REQUEST_METHOD'] == 'POST')
+        if($_SERVER['REQUEST_METHOD'] === 'POST')
         {
-            if(isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'multipart/form-data')
+            if(isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] === 'multipart/form-data')
             {
                 self::parseUploadFiles($http_body, $http_post_boundary);
             }
@@ -224,7 +224,7 @@ class Http
         // other headers
         foreach(HttpCache::$header as $key=>$item)
         {
-            if('Set-Cookie' == $key && is_array($item))
+            if('Set-Cookie' === $key && is_array($item))
             {
                 foreach($item as $it)
                 {
@@ -270,7 +270,7 @@ class Http
             }
         }
     
-        if('location' == strtolower($key) && !$http_response_code)
+        if('location' === strtolower($key) && !$http_response_code)
         {
             return self::header($content, true, 302);
         }
@@ -278,13 +278,13 @@ class Http
         if(isset(HttpCache::$codes[$http_response_code]))
         {
             HttpCache::$header['Http-Code'] = "HTTP/1.1 $http_response_code " .  HttpCache::$codes[$http_response_code];
-            if($key == 'Http-Code')
+            if($key === 'Http-Code')
             {
                 return true;
             }
         }
     
-        if($key == 'Set-Cookie')
+        if($key === 'Set-Cookie')
         {
             HttpCache::$header[$key][] = $content;
         }

+ 4 - 4
Workerman/WebServer.php

@@ -154,9 +154,9 @@ class WebServer extends Worker
         
         $path_info = pathinfo($path);
         $extension = isset($path_info['extension']) ? $path_info['extension'] : '' ;
-        if($extension == '')
+        if($extension === '')
         {
-            $path = ($len = strlen($path)) && $path[$len -1] == '/' ? $path.'index.php' : $path . '/index.php';
+            $path = ($len = strlen($path)) && $path[$len -1] === '/' ? $path.'index.php' : $path . '/index.php';
             $extension = 'php';
         }
         
@@ -165,7 +165,7 @@ class WebServer extends Worker
         $file = "$root_dir/$path";
         
         // 对应的php文件不存在则直接使用根目录的index.php
-        if($extension == 'php' && !is_file($file))
+        if($extension === 'php' && !is_file($file))
         {
             $file = "$root_dir/index.php";
             if(!is_file($file))
@@ -188,7 +188,7 @@ class WebServer extends Worker
             $file = realpath($file);
             
             // 如果请求的是php文件
-            if($extension == 'php')
+            if($extension === 'php')
             {
                 $cwd = getcwd();
                 chdir($root_dir);

+ 11 - 11
Workerman/Worker.php

@@ -464,7 +464,7 @@ class Worker
         {
             // 启动 workerman
             case 'start':
-                if($command2 == '-d')
+                if($command2 === '-d')
                 {
                     Worker::$daemonize = true;
                 }
@@ -516,7 +516,7 @@ class Worker
                         exit(0);
                     }
                     // -d 说明是以守护进程的方式启动
-                    if($command2 == '-d')
+                    if($command2 === '-d')
                     {
                         Worker::$daemonize = true;
                     }
@@ -606,7 +606,7 @@ class Worker
         }
         umask(0);
         $pid = pcntl_fork();
-        if(-1 == $pid)
+        if(-1 === $pid)
         {
             throw new Exception('fork fail');
         }
@@ -614,13 +614,13 @@ class Worker
         {
             exit(0);
         }
-        if(-1 == posix_setsid())
+        if(-1 === posix_setsid())
         {
             throw new Exception("setsid fail");
         }
         // fork again avoid SVR4 system regain the control of terminal
         $pid = pcntl_fork();
-        if(-1 == $pid)
+        if(-1 === $pid)
         {
             throw new Exception("fork fail");
         }
@@ -1008,7 +1008,7 @@ class Worker
         
         // 子进程部分
         $worker = current(self::$_workers);
-        $wrker_status_str = posix_getpid()."\t".str_pad(round(memory_get_usage()/(1024*1024),2)."M", 7)." " .str_pad($worker->getSocketName(), self::$_maxSocketNameLength) ." ".str_pad(($worker->name == $worker->getSocketName() ? 'none' : $worker->name), self::$_maxWorkerNameLength)." ";
+        $wrker_status_str = posix_getpid()."\t".str_pad(round(memory_get_usage()/(1024*1024),2)."M", 7)." " .str_pad($worker->getSocketName(), self::$_maxSocketNameLength) ." ".str_pad(($worker->name === $worker->getSocketName() ? 'none' : $worker->name), self::$_maxWorkerNameLength)." ";
         $wrker_status_str .= str_pad(ConnectionInterface::$statistics['connection_count'], 11)." ".str_pad(ConnectionInterface::$statistics['total_request'], 14)." ".str_pad(ConnectionInterface::$statistics['send_fail'],9)." ".str_pad(ConnectionInterface::$statistics['throw_exception'],15)."\n";
         file_put_contents(self::$_statisticsFile, $wrker_status_str, FILE_APPEND);
     }
@@ -1023,11 +1023,11 @@ class Worker
         {
             $error_msg = "WORKER EXIT UNEXPECTED ";
             $errors = error_get_last();
-            if($errors && ($errors['type'] == E_ERROR ||
-                     $errors['type'] == E_PARSE ||
-                     $errors['type'] == E_CORE_ERROR ||
-                     $errors['type'] == E_COMPILE_ERROR || 
-                     $errors['type'] == E_RECOVERABLE_ERROR ))
+            if($errors && ($errors['type'] === E_ERROR ||
+                     $errors['type'] === E_PARSE ||
+                     $errors['type'] === E_CORE_ERROR ||
+                     $errors['type'] === E_COMPILE_ERROR || 
+                     $errors['type'] === E_RECOVERABLE_ERROR ))
             {
                 $error_msg .= self::getErrorType($errors['type']) . " {$errors['message']} in {$errors['file']} on line {$errors['line']}";
             }