示例#1
0
function master_process($workers)
{
    //监听子进程,如果停止,会再拉起来
    swoole_process::signal(SIGCHLD, function ($signo) use(&$workers) {
        while (1) {
            $ret = swoole_process::wait(false);
            if ($ret) {
                $pid = $ret['pid'];
                //这里实现一个自动拉起的能力
                $child_process = $workers[$pid];
                logprint('info', "Worker Exit, kill_signal={$ret['signal']} PID=" . $pid);
                $new_pid = $child_process->start();
                $workers[$new_pid] = $child_process;
                unset($workers[$pid]);
            } else {
                break;
            }
        }
    });
    //kill -10 结束全部程序
    swoole_process::signal(SIGUSR1, function ($signo) use(&$workers) {
        swoole_process::signal(SIGCHLD, null);
        foreach ($workers as $pid => $worker) {
            swoole_process::kill($pid);
        }
        //处理子进程,然后自己退出
        exit;
    });
}
function export_pleiades()
{
    global $levels_dir;
    global $lastrun_file;
    # Make sure our export folder is there
    if (!is_dir($levels_dir)) {
        passthru("mkdir -p {$levels_dir}");
    }
    if (!is_dir($levels_dir)) {
        logprint("Output directory does not exist and failed to be created.");
        exit;
    }
    # Start export
    logprint("\nExporting pleiades levels to folder '{$levels_dir}'");
    $lastrun_time = get_lastrun_date();
    $master_array = get_database_data($lastrun_time);
    $level_count = count($master_array);
    if ($level_count > 0) {
        logprint("Exporting {$level_count} updated files");
        export_to_files($master_array);
    } else {
        logprint("No new levels to export.");
    }
    # Finally udpate our lastrun file
    # And alter timestamp to match modified time
    touch("{$lastrun_file}", strtotime(date("Y-m-d H:i:s")));
}