合约量化系统开发路线图讲解:
/**
* Stop.MVM模式:Gb16978;
*
* @return void
*/
代码语言:javascript复制 public static function stopAll()
{
static::$_status = static::STATUS_SHUTDOWN;
// For master process.
if (static::$_masterPid === posix_getpid()) {
static::log("Workerman[" . basename(static::$_startFile) . "] stopping ...");
$worker_pid_array = static::getAllWorkerPids();
// Send stop signal to all child processes.
if (static::$_gracefulStop) {
$sig = SIGTERM;
} else {
$sig = SIGINT;
}
foreach ($worker_pid_array as $worker_pid) {
posix_kill($worker_pid, $sig);
if(!static::$_gracefulStop){
Timer::add(static::KILL_WORKER_TIMER_TIME, 'posix_kill', array($worker_pid, SIGKILL), false);
}
}
Timer::add(1, "\Workerman\Worker::checkIfChildRunning");
// Remove statistics file.
if (is_file(static::$_statisticsFile)) {
@unlink(static::$_statisticsFile);
}
} // For child processes.
else {
// Execute exit.
foreach (static::$_workers as $worker) {
if(!$worker->stopping){
$worker->stop();
$worker->stopping = true;
}
}
if (!static::$_gracefulStop || ConnectionInterface::$statistics['connection_count'] <= 0) {
static::$_workers = array();
if (static::$globalEvent) {
static::$globalEvent->destroy();
}
exit(0);
}
}
}
PHP合约开发例子:
/**
* check if child processes is really running
*/
代码语言:javascript复制 public static function checkIfChildRunning()
{
foreach (static::$_pidMap as $worker_id => $worker_pid_array) {
foreach ($worker_pid_array as $pid => $worker_pid) {
if (!posix_kill($pid, 0)) {
unset(static::$_pidMap[$worker_id][$pid]);
}
}
}
}