Skip to content

Commit

Permalink
优化配置加载
Browse files Browse the repository at this point in the history
  • Loading branch information
ywisax committed Dec 6, 2016
1 parent 0aa5756 commit 4dd6bca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
5 changes: 3 additions & 2 deletions demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' => [
Expand Down
13 changes: 7 additions & 6 deletions src/server/HttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class HttpServer extends Server
*/
public $sessionKey = 'JSESSIONID';

/**
* @var string 要打开的链接
*/
public $xhprofLink;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -122,8 +127,6 @@ public function onMessage($connection, $data)
// $t .= '</pre>';
// return $connection->send($t);

//xdebug_start_trace();

if ($this->debug)
{
xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);
Expand Down Expand Up @@ -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";
}
}
}
21 changes: 9 additions & 12 deletions src/server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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,
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 4dd6bca

Please sign in to comment.