Explorar o código

remove ssl && add tcp keepalive

walkor %!s(int64=10) %!d(string=hai) anos
pai
achega
0eaa53f09b
Modificáronse 1 ficheiros con 8 adicións e 42 borrados
  1. 8 42
      Workerman/Worker.php

+ 8 - 42
Workerman/Worker.php

@@ -193,12 +193,6 @@ class Worker
     protected $_context = null;
     
     /**
-     * enable ssl or not
-     * @var bool
-     */
-    protected $_enableSSL = false;
-    
-    /**
      * all instances of worker
      * @var array
      */
@@ -1004,24 +998,19 @@ class Worker
         }
         
         $flags =  $this->transport === 'udp' ? STREAM_SERVER_BIND : STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
-        if($this->_enableSSL)
-        {
-            if($this->transport == 'udp')
-            {
-                throw new Exception('udp do not support ssl');
-            }
-            $this->_mainSocket = stream_socket_server("ssl:".$address, $errno, $errmsg, $flags, $this->_context);
-            @stream_socket_enable_crypto($this->_mainSocket, false);
-        }
-        else 
-        {
-            $this->_mainSocket = stream_socket_server($this->transport.":".$address, $errno, $errmsg, $flags, $this->_context);
-        }
+        $this->_mainSocket = stream_socket_server($this->transport.":".$address, $errno, $errmsg, $flags, $this->_context);
         if(!$this->_mainSocket)
         {
             throw new Exception($errmsg);
         }
         
+        // keepalive
+        if(function_exists('socket_import_stream'))
+        {
+            $socket   = socket_import_stream($this->_mainSocket );
+            socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 1);
+        }
+        
         stream_set_blocking($this->_mainSocket, 0);
         
         if(self::$globalEvent)
@@ -1047,21 +1036,6 @@ class Worker
     }
     
     /**
-     * enable SSL
-     * @param array $option @see http://php.net/manual/zh/context.ssl.php
-     * example $option = array('local_cert' => '/your/path/file.pem', 'passphrase' => 'password', 'allow_self_signed' => true, 'verify_peer' => false)
-     * @return void
-     */
-    public function enableSSL(array $option)
-    {
-        $this->_enableSSL = true;
-        foreach($option as $key => $value)
-        {
-            stream_context_set_option($this->_context, 'ssl', $key, $value);
-        }
-    }
-    
-    /**
      * run the current worker
      */
     public function run()
@@ -1125,14 +1099,6 @@ class Worker
         {
             return;
         }
-        if($this->_enableSSL)
-        {
-            // block the connection until SSL is done
-            stream_set_blocking ($socket, true); 
-            stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv3_SERVER);
-            //unblock connection
-            stream_set_blocking ($socket, false);
-        }
         $connection = new TcpConnection($new_socket);
         $connection->protocol = $this->_protocol;
         $connection->onMessage = $this->onMessage;