/** * Reads pipes, executes callback. * * @param Boolean $blocking Whether to use blocking calls or not. */ private function readPipes($blocking, $close) { if ($close) { $result = $this->processPipes->readAndCloseHandles($blocking); } else { $result = $this->processPipes->read($blocking); } foreach ($result as $type => $data) { if (3 == $type) { $this->fallbackExitcode = (int) $data; } else { call_user_func($this->callback, $type === self::STDOUT ? self::OUT : self::ERR, $data); } } }
/** * Closes process resource, closes file handles, sets the exitcode. * * @return Integer The exitcode */ private function close() { $exitcode = -1; $this->processPipes->close(); if (is_resource($this->process)) { $exitcode = proc_close($this->process); } $this->exitcode = $this->exitcode !== null ? $this->exitcode : -1; $this->exitcode = -1 != $exitcode ? $exitcode : $this->exitcode; if (-1 == $this->exitcode && null !== $this->fallbackExitcode) { $this->exitcode = $this->fallbackExitcode; } elseif (-1 === $this->exitcode && $this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) { // if process has been signaled, no exitcode but a valid termsig, apply unix convention $this->exitcode = 128 + $this->processInformation['termsig']; } return $this->exitcode; }
/** * Closes process resource, closes file handles, sets the exitcode. * * @return int The exitcode */ private function close() { $this->processPipes->close(); if (is_resource($this->process)) { proc_close($this->process); } $this->exitcode = $this->processInformation['exitcode']; $this->status = self::STATUS_TERMINATED; if (-1 === $this->exitcode) { if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) { // if process has been signaled, no exitcode but a valid termsig, apply Unix convention $this->exitcode = 128 + $this->processInformation['termsig']; } elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { $this->processInformation['signaled'] = true; $this->processInformation['termsig'] = -1; } } // Free memory from self-reference callback created by buildCallback // Doing so in other contexts like __destruct or by garbage collector is ineffective // Now pipes are closed, so the callback is no longer necessary $this->callback = null; return $this->exitcode; }