Skip to content

Commit

Permalink
改进
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Mar 8, 2019
1 parent 24f78b3 commit 7ffa64b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ public function swoole(Request $request, Response $response)
}
}

if ($this->isMulti()) {
$this->initialize();
}

$resp = $this->run();
$resp->send();

$content = ob_get_clean();
$status = $resp->getCode();

// Trace调试注入
if ($this->env->get('app_trace', $this->config->get('app_trace'))) {
if ($this->env->get('app_trace', $this->config->get('app.app_trace'))) {
$this->debug->inject($resp, $content);
}

Expand Down
20 changes: 16 additions & 4 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Http extends Server
protected $app;
protected $rootPath;
protected $table;
protected $appInit;
protected $cachetable;
protected $monitor;
protected $server_type;
Expand Down Expand Up @@ -69,6 +70,11 @@ public function setRootPath($path)
$this->rootPath = $path;
}

public function appInit(\Closure $closure)
{
$this->appInit = $closure;
}

public function setMonitor($interval = 2, $path = [])
{
$this->monitor['interval'] = $interval;
Expand Down Expand Up @@ -135,7 +141,12 @@ public function option(array $option)
public function onWorkerStart($server, $worker_id)
{
// 应用实例化
$this->app = new Application($this->rootPath);
$this->app = new Application($this->rootPath);

if ($this->appInit) {
call_user_func_array($this->appInit, [$this->app]);
}

$this->lastMtime = time();

//swoole server worker启动行为
Expand All @@ -160,14 +171,15 @@ public function onWorkerStart($server, $worker_id)
facade\Timer::class => Timer::class,
]);

// 应用初始化
$this->app->initialize();

$this->app->bind([
'cookie' => Cookie::class,
'session' => Session::class,
]);

if (!$this->app->isMulti()) {
$this->app->initialize();
}

$this->initServer($server, $worker_id);

if (0 == $worker_id && $this->monitor) {
Expand Down

0 comments on commit 7ffa64b

Please sign in to comment.