Skip to content

Commit

Permalink
修复当启用守护进程模式时获取错误的 pid 的bug,对一些变量使用前做 isset 判断
Browse files Browse the repository at this point in the history
  • Loading branch information
breath-co2 committed Apr 6, 2017
1 parent 6b840e9 commit 9ca872c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/RemoteShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function __construct($publicKeyFiles = null)
$this->contexts->column('auth', \SWOOLE\Table::TYPE_INT, 1);
$this->contexts->create();

if (self::$server->setting['dispatch_mode'] && in_array(self::$server->setting['dispatch_mode'], [1, 3]))
if (isset(self::$server->setting['swoole']['dispatch_mode']) && self::$server->setting['swoole']['dispatch_mode'] && in_array(self::$server->setting['swoole']['dispatch_mode'], [1, 3]))
{
# 1,3 模式下会屏蔽onConnect/onClose事件
$this->canAutoClear = false;
Expand Down Expand Up @@ -293,7 +293,7 @@ public function onReceive($serv, $fd, $reactorId, $data)
$msg = new \stdClass();
$msg->_sys = true;
$msg->name = '_remoteShell';
$msg->data = __CLASS__ . "\r\n$fd\r\n2\r\n" . $args[1];
$msg->data = __CLASS__ . "\r\n$fd\r\n2\r\n" . (isset($args[1]) ? $args[1] : '');
$serv->sendMessage(serialize($msg), $obj['workerId']);
}
else
Expand Down
14 changes: 12 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ protected function initHosts()

if ($this->config['remote_shell']['open'])
{
$shell = $this->workers['_remoteShell'] = new RemoteShell($this->config['remote_shell']['public_key']?: null);
$shell = $this->workers['_remoteShell'] = new RemoteShell(isset($this->config['remote_shell']['public_key']) ? $this->config['remote_shell']['public_key'] : null);
$rs = $shell->listen($this->server, $host = $this->config['remote_shell']['host'] ?: '127.0.0.1', $port = $this->config['remote_shell']['port']?: 9599);
if ($rs)
{
Expand All @@ -609,6 +609,11 @@ protected function initHosts()
*/
public function onWorkerStart($server, $workerId)
{
if (isset($this->config['swoole']['daemonize']) && $this->config['swoole']['daemonize'] == 1)
{
$this->pid = $this->server->master_pid;
}

if($server->taskworker)
{
# 任务序号
Expand Down Expand Up @@ -881,7 +886,7 @@ public function onFinish($server, $taskId, $data)
*/
public function onTask($server, $taskId, $fromId, $data)
{
if (is_object($data) && $data instanceof \stdClass && $data->_sys === true)
if (is_object($data) && $data instanceof \stdClass && isset($data->_sys) && $data->_sys === true)
{
$serverId = $data->sid;
$data = $data->data;
Expand Down Expand Up @@ -920,6 +925,11 @@ public function onStart($server)
*/
public function onManagerStart($server)
{
if (isset($this->config['swoole']['daemonize']) && $this->config['swoole']['daemonize'] == 1)
{
$this->pid = $this->server->master_pid;
}

$this->setProcessTag('manager');
}

Expand Down

0 comments on commit 9ca872c

Please sign in to comment.