Skip to content

Commit

Permalink
Merge pull request #14 from uniondrug/2.x
Browse files Browse the repository at this point in the history
add checkParent function
  • Loading branch information
xueron authored May 10, 2018
2 parents 350a1f0 + ce93e75 commit efbcb9a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,29 @@ public function runProcess(swoole_process $worker)
// 注册定时器测试
Connections::keepConnections();

// 调用处理进程
parent::runProcess($worker);
}

/**
* 检查父进程状态,如果已经退出,或者不再活跃,子进程自己退出
*/
public function checkParent()
{
if (function_exists('posix_getppid')) {
$parentPid = posix_getppid();
if ($parentPid == 1) {
return false;
} else {
if (!swoole_process::kill($parentPid, 0)) {
return false;
}
}
}

return true;
}

/**
* 通过魔术方法调用服务
*
Expand Down

0 comments on commit efbcb9a

Please sign in to comment.