From 4dd6bca6e87237bed6372523d8d6c1462f376126 Mon Sep 17 00:00:00 2001 From: ywisax <25803471@qq.com> Date: Tue, 6 Dec 2016 14:10:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/index.php | 5 +++-- src/server/HttpServer.php | 13 +++++++------ src/server/Server.php | 21 +++++++++------------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/demo/index.php b/demo/index.php index 8ac41db..94a3fd7 100644 --- a/demo/index.php +++ b/demo/index.php @@ -8,7 +8,8 @@ Yii::$app->params['workermanHttp']['demo'] = [ 'root' => __DIR__, - 'debug' => false, + 'debug' => true, + 'xhprofLink' => 'http://127.0.0.1/xhprof/xhprof_html/index.php?run={tag}&source=xhprof_test', // bootstrap文件, 只会引入一次 'bootstrapFile' => [ __DIR__ . '/config/aliases.php', @@ -23,7 +24,7 @@ 'host' => '127.0.0.1', 'port' => 6677, // 配置参考 http://doc3.workerman.net/worker-development/property.html - 'count' => 4, + 'count' => 1, 'name' => 'demo-http' ], 'task' => [ diff --git a/src/server/HttpServer.php b/src/server/HttpServer.php index 985717a..db9e457 100644 --- a/src/server/HttpServer.php +++ b/src/server/HttpServer.php @@ -32,6 +32,11 @@ class HttpServer extends Server */ public $sessionKey = 'JSESSIONID'; + /** + * @var string 要打开的链接 + */ + public $xhprofLink; + /** * @inheritdoc */ @@ -122,8 +127,6 @@ public function onMessage($connection, $data) // $t .= ''; // return $connection->send($t); - //xdebug_start_trace(); - if ($this->debug) { xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU); @@ -199,15 +202,13 @@ public function onMessage($connection, $data) unset($app); } - //xdebug_stop_trace(); - //xdebug_print_function_stack(); - if ($this->debug) { $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"; + echo $this->xhprofLink ? str_replace('{tag}', $runId, $this->xhprofLink) : $runId; + echo "\n"; } } } diff --git a/src/server/Server.php b/src/server/Server.php index 8e3f0f0..5577704 100644 --- a/src/server/Server.php +++ b/src/server/Server.php @@ -159,11 +159,11 @@ public static function loadBootstrapFile($bootstrapFile) * 运行HTTP服务器 * * @param array $config - * @param static $root - * @param bool $isDebug */ - public static function runAppHttpServer($config, $root, $isDebug) + public static function runAppHttpServer($config) { + $isDebug = ArrayHelper::getValue($config, 'debug', false); + $root = ArrayHelper::getValue($config, 'root'); $serverConfig = (array) ArrayHelper::getValue($config, 'server'); if ($serverConfig) { @@ -172,6 +172,7 @@ public static function runAppHttpServer($config, $root, $isDebug) unset($serverConfig['host'], $serverConfig['port']); /** @var HttpServer $server */ $server = new HttpServer([ + 'xhprofLink' => ArrayHelper::getValue($config, 'xhprofLink'), 'app' => Application::$workerApp, 'host' => $host, 'port' => $port, @@ -186,10 +187,11 @@ public static function runAppHttpServer($config, $root, $isDebug) * 运行任务处理服务器 * * @param array $config - * @param bool $isDebug */ - public static function runAppTaskServer($config, $isDebug) + public static function runAppTaskServer($config) { + // 是否开启调试 + $isDebug = ArrayHelper::getValue($config, 'debug', false); $taskConfig = (array) ArrayHelper::getValue($config, 'task'); if ($taskConfig) { @@ -225,16 +227,11 @@ final public static function runApp($app) // 日志文件 Worker::$logFile = ArrayHelper::getValue($config, 'logFile'); - // 是否开启调试 - $isDebug = ArrayHelper::getValue($config, 'debug', false); - - $root = ArrayHelper::getValue($config, 'root'); - // 执行 HTTP SERVER - self::runAppHttpServer($config, $root, $isDebug); + self::runAppHttpServer($config); // 执行 TASK SERVER - self::runAppTaskServer($config, $isDebug); + self::runAppTaskServer($config); Worker::runAll(); }