예제 #1
0
 public function __construct(StreamProcess $child)
 {
     $this->child = $child;
     $this->protocol = new RpcProtocol($this->child->getReadStream(), $this->child->getWriteStream(), $this->child->getErrorStream(), Factory::create());
     $this->output = '';
     $output =& $this->output;
     $this->protocol->registerOutputCallback(function ($out) use(&$output) {
         $output .= $out;
     });
 }
    if ($process instanceof StreamProcess) {
        $message("Stopping process... ");
        $loop->removeReadStream($process->getReadStream());
        $loop->removeReadStream($process->getErrorStream());
        $process->terminate();
        $process->close();
        echo "done.\n";
    }
};
$start = function () use($loop, $message, $forward, &$process, &$time) {
    $message("Starting process... ");
    $command = INTERPRETER . ' ' . escapeshellarg(realpath(SCRIPT));
    $process = new StreamProcess($command);
    echo "done.\n";
    $loop->addReadStream($process->getReadStream(), $forward);
    $loop->addReadStream($process->getErrorStream(), $forward);
    if (isset($time) === false) {
        $time = microtime(true);
    }
};
$restart = function () use($loop, $stop, $start, &$time) {
    $now = microtime(true);
    if ($now <= $time) {
        return;
    }
    $stop();
    $start();
    $time = microtime(true) + DELAY;
};
$exit = function () use($loop, $stop) {
    $stop();