diff --git a/bin/easyswoole.php b/bin/easyswoole.php index 2bbec7a3..044a2bb4 100644 --- a/bin/easyswoole.php +++ b/bin/easyswoole.php @@ -14,7 +14,7 @@ class Install { public static function init() { - \EasySwoole\Frame\Core::getInstance(); + \EasySwoole\EasySwoole\Core::getInstance(); //强制更新easyswoole bin管理文件 if(is_file(EASYSWOOLE_ROOT . '/easyswoole')){ unlink(EASYSWOOLE_ROOT . '/easyswoole'); @@ -123,7 +123,7 @@ public static function showHelpForReload() public static function showHelp() { - $version = \EasySwoole\Frame\SysConst::VERSION; + $version = \EasySwoole\EasySwoole\SysConst::VERSION; echo <<setArgCallback('start',function ()use($com){ - \EasySwoole\Frame\Core::getInstance()->initialize(); - $conf = \EasySwoole\Frame\Config::getInstance(); + + $conf = \EasySwoole\EasySwoole\Config::getInstance(); if($com->getOptVal('d')){ $conf->setConf("MAIN_SERVER.SETTING.daemonize", true); } @@ -185,13 +185,14 @@ public static function showHelp() Install::showTag('daemonize', $conf->getConf("MAIN_SERVER.SETTING.daemonize")); Install::showTag('swoole version', phpversion('swoole')); Install::showTag('php version', phpversion()); - \EasySwoole\Frame\Core::getInstance()->createServer()->start(); + \EasySwoole\EasySwoole\Core::getInstance()->initialize(); + \EasySwoole\EasySwoole\Core::getInstance()->createServer()->start(); }); $com->setArgCallback('stop',function ()use($com){ $force = $com->getOptVal('f'); - \EasySwoole\Frame\Core::getInstance()->initialize(); - $Conf = \EasySwoole\Frame\Config::getInstance(); + \EasySwoole\EasySwoole\Core::getInstance()->initialize(); + $Conf = \EasySwoole\EasySwoole\Config::getInstance(); $pidFile = $Conf->getConf("MAIN_SERVER.SETTING.pid_file"); if (file_exists($pidFile)) { $pid = file_get_contents($pidFile); @@ -232,8 +233,8 @@ public static function showHelp() $com->setArgCallback('reload',function ()use($com){ $all = $com->getOptVal('a'); - \EasySwoole\Frame\Core::getInstance()->initialize(); - $Conf = \EasySwoole\Frame\Config::getInstance(); + \EasySwoole\EasySwoole\Core::getInstance()->initialize(); + $Conf = \EasySwoole\EasySwoole\Config::getInstance(); $pidFile = $Conf->getConf("MAIN_SERVER.SETTING.pid_file"); if (file_exists($pidFile)) { if (!$all) { diff --git a/composer.json b/composer.json index 545505af..29999d9e 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,11 @@ ], "require": { "php": ">=7.1.0", - "ext-swoole": ">=4.0", + "ext-swoole": ">=4.0.3", + "easyswoole/component": "^1.0", "easyswoole/spl": "^1.0", - "easyswoole/http": "^1.0", "easyswoole/core": "^1.0", + "easyswoole/http": "^1.0", "easyswoole/utility": "^1.0" }, "require-dev": { @@ -24,7 +25,7 @@ }, "autoload": { "psr-4": { - "EasySwoole\\Frame\\": "src/" + "EasySwoole\\EasySwoole\\": "src/" } } } diff --git a/src/AbstractInterface/Event.php b/src/AbstractInterface/Event.php index 43ea24d6..99e01b5a 100644 --- a/src/AbstractInterface/Event.php +++ b/src/AbstractInterface/Event.php @@ -6,7 +6,7 @@ * Time: 下午6:32 */ -namespace EasySwoole\Frame\AbstractInterface; +namespace EasySwoole\EasySwoole\AbstractInterface; use EasySwoole\Core\EventRegister; diff --git a/src/Config.php b/src/Config.php index 25f8fe10..2a625b23 100644 --- a/src/Config.php +++ b/src/Config.php @@ -6,7 +6,7 @@ * Time: 下午5:46 */ -namespace EasySwoole\Frame; +namespace EasySwoole\EasySwoole; use EasySwoole\Component\Singleton; diff --git a/src/Core.php b/src/Core.php index 74e82917..f7e9b793 100644 --- a/src/Core.php +++ b/src/Core.php @@ -6,13 +6,15 @@ * Time: 下午6:07 */ -namespace EasySwoole\Frame; +namespace EasySwoole\EasySwoole; + + use EasySwoole\Component\Di; use EasySwoole\Component\Singleton; use EasySwoole\Core\EventHelper; use EasySwoole\Core\EventRegister; use EasySwoole\Core\ServerManager; -use EasySwoole\Frame\AbstractInterface\Event; +use EasySwoole\EasySwoole\AbstractInterface\Event; use EasySwoole\Http\Request; use EasySwoole\Http\Response; use EasySwoole\Http\WebService; @@ -36,9 +38,9 @@ function initialize() if(file_exists($file)){ require_once $file; try{ - $ref = new \ReflectionClass('EasySwoole\Frame\EasySwooleEvent'); + $ref = new \ReflectionClass('EasySwoole\EasySwoole\EasySwooleEvent'); if(!$ref->implementsInterface(Event::class)){ - die('global file for EasySwooleEvent is not compatible for EasySwoole\Frame\EasySwooleEvent'); + die('global file for EasySwooleEvent is not compatible for EasySwoole\EasySwoole\EasySwooleEvent'); } unset($ref); }catch (\Throwable $throwable){ @@ -124,14 +126,20 @@ private function registerErrorHandler() private function mainServerHook($type) { - if($type != ServerManager::TYPE_SERVER){ + if($type === ServerManager::TYPE_SERVER){ + + }else{ $namespace = Di::getInstance()->get(SysConst::HTTP_CONTROLLER_NAMESPACE); if(empty($namespace)){ $namespace = 'App\\HttpController\\'; } $depth = intval(Di::getInstance()->get(SysConst::HTTP_CONTROLLER_MAX_DEPTH)); $depth = $depth > 5 ? $depth : 5; - $webService = new WebService($namespace,$depth); + $max = intval(Di::getInstance()->get(SysConst::HTTP_CONTROLLER_POOL_MAX_NUM)); + if($max == 0){ + $max = 20; + } + $webService = new WebService($namespace,$depth,$max); $httpExceptionHandler = Di::getInstance()->get(SysConst::HTTP_EXCEPTION_HANDLER); if($httpExceptionHandler){ $webService->setExceptionHandler($httpExceptionHandler); @@ -140,7 +148,10 @@ private function mainServerHook($type) EventHelper::on($server,EventRegister::onRequest,function (\swoole_http_request $request,\swoole_http_response $response)use($webService){ $request_psr = new Request($request); $response_psr = new Response($response); - $webService->onRequest($request_psr,$response_psr); + if(EasySwooleEvent::onRequest($request_psr,$response_psr)){ + $webService->onRequest($request_psr,$response_psr); + } + EasySwooleEvent::afterRequest($request_psr,$response_psr); }); } } diff --git a/src/Resource/EasySwooleEvent.tpl b/src/Resource/EasySwooleEvent.tpl index 09ee8c69..42fb3bfa 100644 --- a/src/Resource/EasySwooleEvent.tpl +++ b/src/Resource/EasySwooleEvent.tpl @@ -6,11 +6,11 @@ * Time: 下午6:33 */ -namespace EasySwoole\Frame; +namespace EasySwoole\EasySwoole; use EasySwoole\Core\EventRegister; -use EasySwoole\Frame\AbstractInterface\Event; +use EasySwoole\EasySwoole\AbstractInterface\Event; use EasySwoole\Http\Request; use EasySwoole\Http\Response; diff --git a/src/SysConst.php b/src/SysConst.php index ffb62000..2fd59f6f 100644 --- a/src/SysConst.php +++ b/src/SysConst.php @@ -6,7 +6,7 @@ * Time: 下午6:24 */ -namespace EasySwoole\Frame; +namespace EasySwoole\EasySwoole; class SysConst @@ -18,5 +18,6 @@ class SysConst const HTTP_CONTROLLER_NAMESPACE = 'HTTP_CONTROLLER_NAMESPACE'; const HTTP_CONTROLLER_MAX_DEPTH = 'CONTROLLER_MAX_DEPTH'; const HTTP_EXCEPTION_HANDLER = 'HTTP_EXCEPTION_HANDLER'; + const HTTP_CONTROLLER_POOL_MAX_NUM = 'HTTP_CONTROLLER_POOL_MAX_NUM'; } \ No newline at end of file