/** * Frees Io watchers from loop. */ public function __destruct() { if (\is_resource($this->handle)) { \pg_close($this->handle); } $this->poll->free(); $this->await->free(); }
/** * {@inheritdoc} * * @param float|int $timeout Timeout for poll if a read was pending. */ public function rebind(float $timeout = 0) { $pending = $this->poll->isPending(); $this->poll->free(); $this->poll = $this->createPoll($this->getResource(), $this->queue); if ($pending) { $this->poll->listen($timeout); } }
/** * {@inheritdoc} * * @param float|int $timeout Timeout for await if a write was pending. */ public function rebind(float $timeout = 0) { if (null !== $this->await) { $pending = $this->await->isPending(); $this->await->free(); $this->await = $this->createAwait($this->getResource(), $this->writeQueue); if ($pending) { $this->await->listen($timeout); } } }
/** * @throws \Icicle\Concurrent\Exception\ProcessException If starting the process fails. * @throws \Icicle\Concurrent\Exception\StatusError If the process is already running. */ public function start() { if (null !== $this->delayed) { throw new StatusError('The process has already been started.'); } $this->delayed = new Delayed(); $fd = [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'a'], ['pipe', 'w']]; $nd = 0 === strncasecmp(PHP_OS, 'WIN', 3) ? 'NUL' : '/dev/null'; $command = sprintf('(%s) 3>%s; code=$?; echo $code >&3; exit $code', $this->command, $nd); $this->process = proc_open($command, $fd, $pipes, $this->cwd ?: null, $this->env ?: null, $this->options); if (!is_resource($this->process)) { throw new ProcessException('Could not start process.'); } $this->oid = getmypid(); $status = proc_get_status($this->process); if (!$status) { proc_close($this->process); $this->process = null; throw new ProcessException('Could not get process status.'); } $this->pid = $status['pid']; $this->stdin = new WritablePipe($pipes[0]); $this->stdout = new ReadablePipe($pipes[1]); $this->stderr = new ReadablePipe($pipes[2]); $stream = $pipes[3]; stream_set_blocking($stream, 0); $this->poll = Loop\poll($stream, function ($resource) { if (!is_resource($resource) || feof($resource)) { $this->close($resource); $this->delayed->reject(new ProcessException('Process ended unexpectedly.')); } else { $code = fread($resource, 1); $this->close($resource); if (!strlen($code) || !is_numeric($code)) { $this->delayed->reject(new ProcessException('Process ended without providing a status code.')); } else { $this->delayed->resolve((int) $code); } } $this->poll->free(); }); }
public function __destruct() { $this->poll->free(); }