Skip to content

Commit fca1383

Browse files
committed
框架性能优化
1 parent cf7ed78 commit fca1383

File tree

8 files changed

+27
-11
lines changed

8 files changed

+27
-11
lines changed

App/Config/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
'default_module' => 'Home', //1:PATHINFO 2:QUERY
1515
'default_controller' => 'Index',
1616
'timeZone'=>'PRC',
17+
'test_mark'=>"cc",
1718
'default_action' => 'index',
1819
'current_module' => '',
1920
'current_controller' => '',
2021
'current_action' => '',
2122
'basePath' => dirname(__DIR__),
23+
'include_files'=>[__DIR__.DIRECTORY_SEPARATOR.'config.php',__DIR__.DIRECTORY_SEPARATOR.'server.php'], //重启工作进程时需要重新载入的配置文件
2224
'log'=>[
2325
'log_dir'=>dirname(__DIR__).DIRECTORY_SEPARATOR.'Log',
2426
'is_display'=>true

App/Modules/Home/Controller/IndexController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public function indexAction(Crypt $crypt,Event $e,SendSmsListener $smlistener,Se
7070

7171
// print_r($userData1);
7272
// print_r($userData2);
73-
$this->assign('name', 'Http Server !!!');
73+
print_r(ServerManager::getApp());
74+
$this->assign('name', 'Http Server sssss !!!');
7475
$this->display('index.html');
7576

7677
}

App/Service/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ class User
1919

2020
public $crypt;
2121

22+
public $name="userService";
2223
public function __construct(Crypt $crypt)
2324
{
2425
$this->crypt=$crypt;
26+
$this->name=$this->name."=>".date("Y-m-d H:i:s");
2527
}
2628

2729
public function findUser()

Framework/SwServer/AbstractServerApplication.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function init()
4040
(isset(ServerManager::$config['log']) && ServerManager::$config['log']) && Log::getInstance()->setConfig(ServerManager::$config['log']);
4141
Db::setConfig(ServerManager::$config['components']['db']['config']);
4242
$this->setApp();
43-
ServerManager::configure(ServerManager::$app[$this->coroutine_id], ServerManager::$config);
43+
//ServerManager::configure(ServerManager::$app[$this->coroutine_id], ServerManager::$config);
4444
}
4545

4646
public function setTimeZone($value)
@@ -99,7 +99,11 @@ public function __get($name)
9999
if ($res) {
100100
return $res;
101101
} else {
102-
parent::__get($name);
102+
if(isset(ServerManager::$config[$name])){
103+
return ServerManager::$config[$name];
104+
}else{
105+
parent::__get($name);
106+
}
103107
}
104108
}
105109
use ServerTrait;

Framework/SwServer/BaseServerManager.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class BaseServerManager
1919
public static $pidFile;
2020
public static $server;
2121
public $swoole_server;
22-
public static $config;
22+
public static $config = [];
2323
public $coroutine_id;
2424

2525
protected static $pack_check_type = 'length';
@@ -152,7 +152,7 @@ public static function getWorkersPid()
152152

153153
/**
154154
* setWorkerUserGroup 设置worker进程的工作组,默认是root
155-
* @param string $worker_user
155+
* @param string $worker_user
156156
*/
157157
public static function setWorkerUserGroup($worker_user = null)
158158
{
@@ -167,7 +167,7 @@ public static function setWorkerUserGroup($worker_user = null)
167167

168168
/**
169169
* getIncludeFiles 获取woker启动前已经加载的文件
170-
* @param string $dir
170+
* @param string $dir
171171
* @return void
172172
*/
173173
public static function getIncludeFiles($dir = 'Http')
@@ -192,15 +192,17 @@ public static function getIncludeFiles($dir = 'Http')
192192

193193
/**
194194
* startInclude 设置需要在workerstart启动时加载的配置文件
195-
* @param array $includes
195+
* @param array $includes
196196
* @return void
197197
*/
198198
public static function startInclude()
199199
{
200200
$includeFiles = isset(static::$config['include_files']) ? static::$config['include_files'] : [];
201+
self::$config = [];
201202
if ($includeFiles) {
202203
foreach ($includeFiles as $filePath) {
203-
include_once $filePath;
204+
$currentIncludeConfigs = include $filePath;
205+
self::$config = array_merge(self::$config, $currentIncludeConfigs);
204206
}
205207
}
206208
}

Framework/SwServer/Component/Invoker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Created by PhpStorm.
3+
* 方法回调超时抛异常
44
* User: hdeng
55
* Date: 2018/12/7
66
* Time: 9:05

Framework/SwServer/Pool/DiPool.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2-
//容器池
2+
/**
3+
* 容器对象池
4+
*/
35

46
namespace Framework\SwServer\Pool;
57
use \Framework\Traits\ComponentTrait;
@@ -52,6 +54,5 @@ public function get($name)
5254
}
5355
}
5456
}
55-
5657
use ComponentTrait, ServiceTrait, ContainerTrait;
5758
}

Framework/SwServer/Protocol/WebServer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ function onWorkerStart($server, $worker_id)
6262
ServerManager::$serverApp = \serialize($app);
6363
}
6464

65+
function onWorkerStop($server, $worker_id){
66+
67+
}
68+
6569
function onConnect($server, $client_id, $from_id)
6670
{
6771
// TODO: Implement onConnect() method.

0 commit comments

Comments
 (0)