소스 검색

select timeout fix

walkor 10 년 전
부모
커밋
9a9163ac46
3개의 변경된 파일17개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      applications/Statistics/Lib/functions.php
  2. 1 1
      workerman/Common/Protocols/Http/Http.php
  3. 15 1
      workerman/Core/Events/Select.php

+ 1 - 1
applications/Statistics/Lib/functions.php

@@ -31,7 +31,7 @@ function multiRequest($request_buffer_array)
     // 轮询处理数据
     while(count($read) > 0)
     {
-        if(stream_select($read, $write, $except, 0, 200000))
+        if(@stream_select($read, $write, $except, 0, 200000))
         {
             foreach($read as $socket)
             {

+ 1 - 1
workerman/Common/Protocols/Http/Http.php

@@ -159,7 +159,7 @@ function http_start($http_string, $SERVER = array())
     // 需要解析$_POST
     if($_SERVER['REQUEST_METHOD'] == 'POST')
     {
-        if($_SERVER['CONTENT_TYPE'] == 'multipart/form-data')
+        if(isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'multipart/form-data')
         {
             parse_upload_files($http_body, $http_post_boundary);
         }

+ 15 - 1
workerman/Core/Events/Select.php

@@ -35,6 +35,20 @@ class Select implements BaseEvent
     public $writeFds = array();
     
     /**
+     * 构造函数 创建一个管道,避免select空fd
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->channel = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+        if($this->channel)
+        {
+            stream_set_blocking($this->channel[0], 0);
+            $this->readFds[0] = $this->channel[0];
+        }
+    }
+    
+    /**
      * 添加事件
      * @see \Man\Core\Events\BaseEvent::add()
      */
@@ -121,7 +135,7 @@ class Select implements BaseEvent
             // 触发信号处理函数
             pcntl_signal_dispatch();
             // stream_select false:出错 ; 0:超时
-            if(!($ret = @stream_select($read, $write, $e, PHP_INT_MAX)))
+            if(!($ret = @stream_select($read, $write, $e, 60)))
             {
                 // 超时
                 if($ret === 0)