Преглед изворни кода

AsyncTcpConnection connect fail detail message

walkor пре 9 година
родитељ
комит
74f57d18db
1 измењених фајлова са 21 додато и 8 уклоњено
  1. 21 8
      Connection/AsyncTcpConnection.php

+ 21 - 8
Connection/AsyncTcpConnection.php

@@ -30,6 +30,13 @@ class AsyncTcpConnection extends TcpConnection
     public $onConnect = null;
 
     /**
+     * Transport layer protocol.
+     *
+     * @var string
+     */
+    public $transport = 'tcp';
+
+    /**
      * Status.
      *
      * @var int
@@ -44,6 +51,13 @@ class AsyncTcpConnection extends TcpConnection
     protected $_remoteHost = '';
 
     /**
+     * Connect start time.
+     *
+     * @var string
+     */
+    protected $_connectStartTime = 0;
+
+    /**
      * PHP built-in protocols.
      *
      * @var array
@@ -59,13 +73,6 @@ class AsyncTcpConnection extends TcpConnection
     );
 
     /**
-     * Transport layer protocol.
-     *
-     * @var string
-     */
-    public $transport = 'tcp';
-
-    /**
      * Construct.
      *
      * @param string $remote_address
@@ -97,8 +104,14 @@ class AsyncTcpConnection extends TcpConnection
         $this->maxSendBufferSize = self::$defaultMaxSendBufferSize;
     }
 
+    /**
+     * Do connect.
+     *
+     * @return void 
+     */
     public function connect()
     {
+        $this->_connectStartTime = microtime(true);
         // Open socket connection asynchronously.
         $this->_socket = stream_socket_client("{$this->transport}://{$this->_remoteAddress}", $errno, $errstr, 0,
             STREAM_CLIENT_ASYNC_CONNECT);
@@ -187,7 +200,7 @@ class AsyncTcpConnection extends TcpConnection
             }
         } else {
             // Connection failed.
-            $this->emitError(WORKERMAN_CONNECT_FAIL, 'connect fail');
+            $this->emitError(WORKERMAN_CONNECT_FAIL, 'connect ' . $this->_remoteAddress . ' fail after ' . round(microtime(true) - $this->_connectStartTime, 4) . ' seconds');
             $this->destroy();
             $this->onConnect = null;
         }