コード例 #1
0
ファイル: Master.php プロジェクト: renwuxun/phpserver
 public function demonize()
 {
     $this->signal->registerHandler(SIGTTOU, function () {
     });
     $this->signal->registerHandler(SIGTTIN, function () {
     });
     $this->signal->registerHandler(SIGTSTP, function () {
     });
     $this->signal->registerHandler(SIGHUP, function () {
     });
     if (static::internalFork()) {
         exit(0);
     } else {
         posix_setsid();
         if (static::internalFork()) {
             exit(0);
         }
         umask(0);
         PHPServer_Helper::writePidFile($this->pidFile);
     }
 }
コード例 #2
0
ファイル: testserver.php プロジェクト: renwuxun/phpserver
<?php

/**
 * Created by PhpStorm.
 * User: mofan
 * Date: 2016/8/5 0005
 * Time: 17:56
 */
set_time_limit(0);
require __DIR__ . '/autoload.php';
$cmd = isset($argv[1]) ? $argv[1] : 'start';
PHPServer_Helper::checkContinue($cmd, $argv[0] . '.pid');
class MyWorker extends PHPServer_Worker
{
    public function job()
    {
        $loopTimes = 0;
        do {
            echo posix_getpid() . ' say hi' . PHP_EOL;
            sleep(1);
        } while (!$this->ifShouldExit() && $loopTimes++ < 10);
        exit(1);
        // worker will be restart if exit code != 0
    }
    public function callFromMasterOnError($status)
    {
        echo 'worker exit on err' . PHP_EOL;
    }
    public function callFromMasterOnSuccess($status)
    {
        echo 'worker exit on suc' . PHP_EOL;