Explorar o código

status add connection statistics

walkor %!s(int64=10) %!d(string=hai) anos
pai
achega
d7c7e1c64b

+ 1 - 1
Workerman/Connection/AsyncTcpConnection.php

@@ -83,6 +83,7 @@ class AsyncTcpConnection extends TcpConnection
                 Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));
             }
             $this->_status = self::STATUS_ESTABLISH;
+            ConnectionInterface::$statistics['connection_count']++;
             if($this->onConnect)
             {
                 try 
@@ -160,5 +161,4 @@ class AsyncTcpConnection extends TcpConnection
             $this->_sendBuffer .= $send_buffer;
         }
     }
-    
 }

+ 1 - 0
Workerman/Connection/ConnectionInterface.php

@@ -17,6 +17,7 @@ abstract class  ConnectionInterface
      * @var array
      */
     public static $statistics = array(
+        'connection_count'=>0,
         'total_request'   => 0, 
         'throw_exception' => 0,
         'send_fail'       => 0,

+ 1 - 0
Workerman/Connection/TcpConnection.php

@@ -416,6 +416,7 @@ class TcpConnection extends ConnectionInterface
      */
     protected function destroy()
     {
+       self::$statistics['connection_count']--;
        if($this->onClose)
        {
            try

+ 4 - 3
Workerman/Worker.php

@@ -21,7 +21,7 @@ class Worker
      * workerman version
      * @var string
      */
-    const VERSION = '3.0.2';
+    const VERSION = '3.0.3';
     
     /**
      * status starting
@@ -920,7 +920,7 @@ class Worker
                 }
             }
             file_put_contents(self::$_statisticsFile,  "---------------------------------------PROCESS STATUS-------------------------------------------\n", FILE_APPEND);
-            file_put_contents(self::$_statisticsFile, "pid\tmemory  ".str_pad('listening', self::$_maxSocketNameLength)." ".str_pad('worker_name', self::$_maxWorkerNameLength)." ".str_pad('total_request', 13)." ".str_pad('send_fail', 9)." ".str_pad('throw_exception', 15)."\n", FILE_APPEND);
+            file_put_contents(self::$_statisticsFile, "pid\tmemory  ".str_pad('listening', self::$_maxSocketNameLength)." ".str_pad('worker_name', self::$_maxWorkerNameLength)." connection ".str_pad('total_request', 13)." ".str_pad('send_fail', 9)." ".str_pad('throw_exception', 15)."\n", FILE_APPEND);
             
             chmod(self::$_statisticsFile, 0722);
             
@@ -934,7 +934,7 @@ class Worker
         // for worker process
         $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 .=  str_pad(ConnectionInterface::$statistics['total_request'], 14)." ".str_pad(ConnectionInterface::$statistics['send_fail'],9)." ".str_pad(ConnectionInterface::$statistics['throw_exception'],15)."\n";
+        $wrker_status_str .= str_pad(ConnectionInterface::$statistics['connection_count'], 10)." ".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);
     }
     
@@ -1110,6 +1110,7 @@ class Worker
         {
             return;
         }
+        ConnectionInterface::$statistics['connection_count']++;
         $connection = new TcpConnection($new_socket);
         $connection->protocol = $this->_protocol;
         $connection->onMessage = $this->onMessage;