walkor 11 лет назад
Родитель
Сommit
dd5c444fc7

+ 1 - 1
applications/ChatDemo/Bootstrap/Gateway.php

@@ -278,7 +278,7 @@ class Gateway extends Man\Core\SocketWorker
     protected function sendBufferToWorker($bin_data)
     {
         $client = stream_socket_client($this->workerAddresses[array_rand($this->workerAddresses)]);
-        $len = stream_socket_sendto($client, $bin_data);
+        $len = fwrite($client, $bin_data);
         return $len == strlen($bin_data);
     }
     

+ 3 - 3
workerman/Core/Master.php

@@ -172,6 +172,8 @@ class Master
         self::notice("\033[1A\n\033[KWorkerman start success ...\033[0m", true);
         // 标记服务状态为运行中
         self::$serviceStatus = self::STATUS_RUNNING;
+        // 初始化任务
+        \Man\Core\Lib\Task::init();
         // 关闭标准输出
         self::resetStdFd();
         // 主循环
@@ -556,9 +558,7 @@ class Master
         $siginfo = array();
         while(1)
         {
-            @pcntl_sigtimedwait(array(SIGCHLD), $siginfo, 1);
-            // 初始化任务系统
-            Lib\Task::tick();
+            sleep(1);
             // 检查是否有进程退出
             self::checkWorkerExit();
             // 触发信号处理

+ 8 - 2
workerman/Core/SocketWorker.php

@@ -532,7 +532,7 @@ abstract class SocketWorker extends AbstractWorker
         // tcp
         if($this->protocol != 'udp')
         {
-            $send_len = @stream_socket_sendto($this->connections[$this->currentDealFd], $str_to_send);
+            $send_len = @fwrite($this->connections[$this->currentDealFd], $str_to_send);
             if($send_len === strlen($str_to_send))
             {
                 return true;
@@ -545,6 +545,12 @@ abstract class SocketWorker extends AbstractWorker
             {
                 $this->sendBuffers[$this->currentDealFd] = $str_to_send;
             }
+            if(!isset($this->connections[$this->currentDealFd]))
+            {
+                $debug_str = new \Exception('sendToClient fail $this->connections[$this->currentDealFd] is null');
+                $this->notice((string)$debug_str);
+                return false;
+            }
             if(feof($this->connections[$this->currentDealFd]))
             {
                 return false;
@@ -570,7 +576,7 @@ abstract class SocketWorker extends AbstractWorker
             return false;
         }
         
-        $send_len = @stream_socket_sendto($this->connections[$fd], $this->sendBuffers[$fd]);
+        $send_len = @fwrite($this->connections[$fd], $this->sendBuffers[$fd]);
         if($send_len === strlen($this->sendBuffers[$fd]))
         {
             if(!$this->isPersistentConnection)