diff --git a/README.md b/README.md index 05384c1..89cb83b 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,11 @@ yii2-swoole和php-fpm下的FeehiCMS 'swoole' => [ 'class' => feehi\console\SwooleController::className(), 'rootDir' => str_replace('console/config', '', __DIR__ ),//yii2项目根路径 - 'app' => 'frontend',//app目录地址 + 'type' => 'advanced',//yii2项目类型,默认为advanced。此处还可以为basic + 'app' => 'frontend',//app目录地址,如果type为basic,这里一般为空 'host' => '127.0.0.1',//监听地址 'port' => 9999,//监听端口 - 'web' => 'web',//默认为web。rootDir app web目的是拼接yii2的根目录,如果你的应用为basic,那么frontend为空即可。 + 'web' => 'web',//默认为web。rootDir app web目的是拼接yii2的根目录,如果你的应用为basic,那么app为空即可。 'debug' => true,//默认开启debug,上线应置为false 'env' => 'dev',//默认为dev,上线应置为prod 'swooleConfig' => [//标准的swoole配置项都可以再此加入 @@ -87,7 +88,7 @@ yii2-swoole和php-fpm下的FeehiCMS 'app' => 'backend', 'host' => '127.0.0.1', 'port' => 9998, - 'web' => 'web',//默认为web。rootDir app web目的是拼接yii2的根目录,如果你的应用为basic,那么frontend为空即可。 + 'web' => 'web',//默认为web。rootDir app web目的是拼接yii2的根目录,如果你的应用为basic,那么app为空即可。 'debug' => true,//默认开启debug,上线应置为false 'env' => 'dev',//默认为dev,上线应置为prod 'swooleConfig' => [ diff --git a/src/console/SwooleController.php b/src/console/SwooleController.php index 3e4b45a..8f1c3c0 100644 --- a/src/console/SwooleController.php +++ b/src/console/SwooleController.php @@ -38,7 +38,9 @@ class SwooleController extends \yii\console\Controller public $rootDir = ""; - public $app = "frontend"; + public $type = "advanced"; + + public $app = "frontend";//如果type为basic,这里默认为空 public $web = "web"; @@ -65,7 +67,7 @@ public function actionStart() $logDir = dirname($this->swooleConfig['log_file']); if( !file_exists($logDir) ) FileHelper::createDirectory($logDir); - $rootDir = $this->rootDir;//网站根目录,basic为下载下来的yii2目录,advanced为frontend或backend的目录 + $rootDir = $this->rootDir;//yii2项目根目录 $web = $rootDir . $this->app . DIRECTORY_SEPARATOR . $this->web;; defined('YII_DEBUG') or define('YII_DEBUG', $this->debug); @@ -73,15 +75,19 @@ public function actionStart() require($rootDir . '/vendor/autoload.php'); //require($rootDir . '/vendor/yiisoft/yii2/Yii.php'); - require($rootDir . '/common/config/bootstrap.php'); - require($rootDir . $this->app . '/config/bootstrap.php'); - - $config = ArrayHelper::merge( - require($rootDir . '/common/config/main.php'), - require($rootDir . '/common/config/main-local.php'), - require($rootDir . $this->app . '/config/main.php'), - require($rootDir . $this->app . '/config/main-local.php') - ); + if( $this->type == 'basic' ){ + $config = require($rootDir . '/config/web.php'); + }else { + require($rootDir . '/common/config/bootstrap.php'); + require($rootDir . $this->app . '/config/bootstrap.php'); + + $config = ArrayHelper::merge( + require($rootDir . '/common/config/main.php'), + require($rootDir . '/common/config/main-local.php'), + require($rootDir . $this->app . '/config/main.php'), + require($rootDir . $this->app . '/config/main-local.php') + ); + } $this->swooleConfig = array_merge([ 'document_root' => $web, @@ -95,6 +101,7 @@ public function actionStart() * @param \swoole_http_response $response */ $server->runApp = function ($request, $response) use ($config, $web) { + $yiiBeginAt = microtime(true); $aliases = [ '@web' => '', '@webroot' => $web, @@ -113,7 +120,7 @@ public function actionStart() ]; $config['components']['response'] = isset($config['components']['response']) ? array_merge($config['components']['response'], $responseComponent) : $responseComponent; - $config['components']['session'] = isset($config['components']['session']) ? array_merge(['savePath'=>$web . '/../session'], $config['components']['session'], ["class" => Session::className()]) : ["class" => Session::className(), 'savePath'=>$web . '/../session']; + $config['components']['session'] = isset($config['components']['session']) ? array_merge(['savePath'=>$web . '/../runtime/session'], $config['components']['session'], ["class" => Session::className()]) : ["class" => Session::className(), 'savePath'=>$web . '/../session']; $config['components']['errorHandler'] = isset($config['components']['errorHandler']) ? array_merge($config['components']['errorHandler'], ["class" => ErrorHandler::className()]) : ["class" => ErrorHandler::className()]; @@ -133,7 +140,7 @@ public function actionStart() try { $application = new Application($config); - yii::$app->getLog()->yiiBeginAt = microtime(true); + yii::$app->getLog()->yiiBeginAt = $yiiBeginAt; yii::$app->setAliases($aliases); try { $application->state = Application::STATE_BEFORE_REQUEST;