/**
  * @param string $name
  * @param $args
  * @return mixed
  * @throws Exception
  */
 public function call($name, array $args)
 {
     if (!$this->child->isRunning()) {
         throw new Exception('Child Process died');
     }
     return $this->protocol->sendCall($name, $args);
 }
 /**
  * @return StreamProcess
  * @throws Exception
  */
 private function spawnChildProcess()
 {
     $childBin = $this->childBinPath;
     if (!is_file($childBin)) {
         throw new Exception('child.php not found generate it using bin/generateChild.php');
     }
     $cwd = false;
     if ($this->workingDirectory) {
         $cwd = getcwd();
         chdir($this->workingDirectory);
     }
     $cmd = sprintf('%s %s %s', $this->phpPath, $this->compileArgs(), escapeshellarg(realpath($childBin)));
     $child = new StreamProcess($cmd);
     if ($cwd) {
         chdir($cwd);
     }
     if (!$child->isOpen() || !$child->isRunning()) {
         throw new Exception('Failed to spawn child process');
     }
     return $child;
 }
    echo date('[H:i:s] > '), implode($delimiter, explode("\n", rtrim($data))), "\n";
};
$stop = function () use($loop, $message, &$process) {
    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;