浏览代码

performance optimization

walkor 5 年之前
父节点
当前提交
f63892c1c9
共有 1 个文件被更改,包括 9 次插入10 次删除
  1. 9 10
      Protocols/Http.php

+ 9 - 10
Protocols/Http.php

@@ -82,26 +82,25 @@ class Http
      */
     public static function decode($recv_buffer, TcpConnection $connection)
     {
-        $md5 = md5($recv_buffer);
-        if (isset(static::$_cache[$md5])) {
+        if (isset(static::$_cache[$recv_buffer])) {
             HttpCache::reset();
-            $cache = static::$_cache[$md5];
-            $cache['server']['REQUEST_TIME_FLOAT'] =  \microtime(true);
-            $cache['server']['REQUEST_TIME'] =  (int)$cache['server']['REQUEST_TIME_FLOAT'];
+            $cache = static::$_cache[$recv_buffer];
+            //$cache['server']['REQUEST_TIME_FLOAT'] =  \microtime(true);
+            //$cache['server']['REQUEST_TIME'] =  (int)$cache['server']['REQUEST_TIME_FLOAT'];
             $_SERVER = $cache['server'];
             $_POST = $cache['post'];
             $_GET = $cache['get'];
             $_COOKIE = $cache['cookie'];
             $_REQUEST = $cache['request'];
             $GLOBALS['HTTP_RAW_POST_DATA'] = $GLOBALS['HTTP_RAW_REQUEST_DATA'] = '';
-            return static::$_cache[$md5];
+            return static::$_cache[$recv_buffer];
         }
         // Init.
         $_POST = $_GET = $_COOKIE = $_REQUEST = $_SESSION = $_FILES = array();
         $GLOBALS['HTTP_RAW_POST_DATA'] = '';
         // Clear cache.
         HttpCache::reset();
-        $microtime = \microtime(true);
+        //$microtime = \microtime(true);
         // $_SERVER
         $_SERVER = array(
             'QUERY_STRING'         => '',
@@ -120,8 +119,8 @@ class Http
             'CONTENT_TYPE'         => '',
             'REMOTE_ADDR'          => '',
             'REMOTE_PORT'          => '0',
-            'REQUEST_TIME'         => (int)$microtime,
-            'REQUEST_TIME_FLOAT'   => $microtime //compatible php5.4
+            //'REQUEST_TIME'         => (int)$microtime,
+            //'REQUEST_TIME_FLOAT'   => $microtime //compatible php5.4
         );
 
         // Parse headers.
@@ -231,7 +230,7 @@ class Http
         $_SERVER['REMOTE_PORT'] = $connection->getRemotePort();
         $ret = array('get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE, 'server' => $_SERVER, 'files' => $_FILES, 'request'=>$_REQUEST);
         if ($_SERVER['REQUEST_METHOD'] === 'GET') {
-            static::$_cache[$md5] = $ret;
+            static::$_cache[$recv_buffer] = $ret;
             if (\count(static::$_cache) > 256) {
                 unset(static::$_cache[key(static::$_cache)]);
             }