Skip to content

Commit

Permalink
修正守护进程的问题 增加app_path配置参数
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jul 4, 2018
1 parent b00180c commit 7211870
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class Swoole extends Server
{
protected $app;
protected $appPath;

/**
* 架构函数
Expand All @@ -33,6 +34,11 @@ public function __construct($host, $port, $ssl = false)
}
}

public function setAppPath($path)
{
$this->appPath = $path;
}

public function option(array $option)
{
// 设置参数
Expand Down Expand Up @@ -72,7 +78,7 @@ public function onStart($server)
public function onWorkerStart($server, $worker_id)
{
// 应用实例化
$this->app = new Application;
$this->app = new Application($this->appPath);

// 应用初始化
$this->app->initialize();
Expand Down
5 changes: 5 additions & 0 deletions src/command/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ protected function start()

$swoole = new SwooleServer($host, $port, $ssl);

// 开启守护进程模式
if ($this->input->hasOption('daemon')) {
$this->config['daemonize'] = true;
}

// 设置应用目录
$swoole->setAppPath($this->config['app_path']);

// 设置服务器参数
$swoole->option($this->config);

$this->output->writeln("Swoole http server started: <http://{$host}:{$port}>");
Expand Down
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// 扩展自身配置
'host' => '0.0.0.0', // 监听地址
'port' => 9501, // 监听端口
'app_path' => '', // 应用地址 如果开启了 'daemonize'=>true 必须设置(使用绝对路径)

// 可以支持swoole的所有配置参数
'pid_file' => Env::get('runtime_path') . 'swoole.pid',
Expand Down

0 comments on commit 7211870

Please sign in to comment.