From b286960dc970da6d3b3c9638ebaa1d10aaf1a4da Mon Sep 17 00:00:00 2001 From: ywisax <25803471@qq.com> Date: Wed, 16 Nov 2016 03:28:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?/=E7=9A=84=E5=80=BC=E6=98=AF=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E6=97=B6=E9=A2=9D=E5=A4=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/ServerController.php | 3 +++ src/server/HttpServer.php | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands/ServerController.php b/src/commands/ServerController.php index 2061adb..b76d479 100644 --- a/src/commands/ServerController.php +++ b/src/commands/ServerController.php @@ -3,6 +3,7 @@ namespace tourze\workerman\yii2\commands; use tourze\workerman\yii2\server\HttpServer; +use Workerman\Worker; use Yii; use yii\console\Controller; @@ -28,5 +29,7 @@ public function actionHttp($app) /** @var HttpServer $server */ $server = new HttpServer; $server->run($app); + + Worker::runAll(); } } diff --git a/src/server/HttpServer.php b/src/server/HttpServer.php index e570da6..a8a5126 100644 --- a/src/server/HttpServer.php +++ b/src/server/HttpServer.php @@ -87,8 +87,6 @@ public function run($app) $_SERVER['SERVER_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_NAME'] = 'localhost'; - - Worker::runAll(); } /** @@ -226,6 +224,14 @@ public function onMessage($connection, $data) $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true); $_SERVER['REQUEST_TIME'] = time(); + $_GET = http_build_query($_GET); + parse_str($_GET, $_GET); + $_POST = http_build_query($_POST); + parse_str($_POST, $_POST); + $_COOKIE = http_build_query($_COOKIE); + parse_str($_COOKIE, $_COOKIE); + $_REQUEST = array_merge($_GET, $_POST); + // $connection->send(print_r($_SERVER, true)); // return; From 07995044d2b9c747fbf3991ef211a58b4b644b80 Mon Sep 17 00:00:00 2001 From: ywisax <25803471@qq.com> Date: Wed, 16 Nov 2016 16:21:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/HttpServer.php | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/server/HttpServer.php b/src/server/HttpServer.php index a8a5126..d7ce915 100644 --- a/src/server/HttpServer.php +++ b/src/server/HttpServer.php @@ -194,13 +194,6 @@ public function onMessage($connection, $data) // $t .= ''; // return $connection->send($t); - //xdebug_start_trace(); - - if ($this->xhprofDebug) - { - xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU); - } - $_SERVER['REQUEST_SCHEME'] = 'http'; $urlInfo = parse_url($_SERVER['REQUEST_URI']); //var_dump($urlInfo); @@ -217,6 +210,11 @@ public function onMessage($connection, $data) } else { + if ($this->xhprofDebug) + { + xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU); + } + $file = $this->root . '/' . $this->indexFile; $_SERVER['SCRIPT_FILENAME'] = $file; $_SERVER['DOCUMENT_ROOT'] = $this->root; @@ -232,8 +230,8 @@ public function onMessage($connection, $data) parse_str($_COOKIE, $_COOKIE); $_REQUEST = array_merge($_GET, $_POST); -// $connection->send(print_r($_SERVER, true)); -// return; + //$connection->send(print_r($_SERVER, true)); + //return; // 使用clone, 原型模式 // 所有请求都clone一个原生$app对象 @@ -286,17 +284,14 @@ public function onMessage($connection, $data) // 还原环境变量 Yii::$app = $this->app; unset($app); - } - - //xdebug_stop_trace(); - //xdebug_print_function_stack(); - if ($this->xhprofDebug) - { - $xhprofData = xhprof_disable(); - $xhprofRuns = new \XHProfRuns_Default(); - $runId = $xhprofRuns->save_run($xhprofData, 'xhprof_test'); - echo "http://127.0.0.1/xhprof/xhprof_html/index.php?run=" . $runId . '&source=xhprof_test'."\n"; + if ($this->xhprofDebug) + { + $xhprofData = xhprof_disable(); + $xhprofRuns = new \XHProfRuns_Default(); + $runId = $xhprofRuns->save_run($xhprofData, 'xhprof_test'); + echo "http://127.0.0.1/xhprof/xhprof_html/index.php?run=" . $runId . '&source=xhprof_test'."\n"; + } } } } From d4b569b146a6cb74a22f095de2fa9970da9dae0b Mon Sep 17 00:00:00 2001 From: ywisax <25803471@qq.com> Date: Fri, 18 Nov 2016 01:40:02 +0800 Subject: [PATCH 3/3] new UrlManager --- src/Container.php | 2 +- src/web/UrlManager.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/web/UrlManager.php diff --git a/src/Container.php b/src/Container.php index 96b6b80..07fc458 100644 --- a/src/Container.php +++ b/src/Container.php @@ -34,6 +34,7 @@ class Container extends \yii\di\Container 'yii\web\ErrorHandler' => 'tourze\workerman\yii2\web\ErrorHandler', 'yii\web\User' => 'tourze\workerman\yii2\web\User', 'yii\web\View' => 'tourze\workerman\yii2\web\View', + 'yii\web\UrlManager' => 'tourze\workerman\yii2\web\UrlManager', ]; /** @@ -203,7 +204,6 @@ class Container extends \yii\di\Container 'yii\web\JsonResponseFormatter', 'yii\web\Link', 'yii\web\MultipartFormDataParser', - 'yii\web\UrlManager', 'yii\web\UrlNormalizer', 'yii\web\UrlRule', 'yii\web\UserEvent', diff --git a/src/web/UrlManager.php b/src/web/UrlManager.php new file mode 100644 index 0000000..5877536 --- /dev/null +++ b/src/web/UrlManager.php @@ -0,0 +1,14 @@ +