/** * Checks if the test is still running. * @return bool */ public function isRunning() { if (!is_resource($this->stdout)) { return FALSE; } $this->output .= stream_get_contents($this->stdout); if ($this->stderr) { $this->errorOutput .= stream_get_contents($this->stderr); } $status = proc_get_status($this->proc); if ($status['running']) { return TRUE; } fclose($this->stdout); if ($this->stderr) { fclose($this->stderr); } $code = proc_close($this->proc); $this->exitCode = $code === self::CODE_NONE ? $status['exitcode'] : $code; if ($this->interpreter->isCgi() && count($tmp = explode("\r\n\r\n", $this->output, 2)) >= 2) { list($headers, $this->output) = $tmp; foreach (explode("\r\n", $headers) as $header) { $a = strpos($header, ':'); if ($a !== FALSE) { $this->headers[trim(substr($header, 0, $a))] = (string) trim(substr($header, $a + 1)); } } } return FALSE; }
/** @return void */ private function createPhpInterpreter() { $args = ''; if ($this->options['-c']) { $args .= ' -c ' . Helpers::escapeArg($this->options['-c']); } elseif (!$this->options['--info']) { echo "Note: No php.ini is used.\n"; } foreach ($this->options['-d'] as $item) { $args .= ' -d ' . Helpers::escapeArg($item); } // Is the executable Zend PHP or HHVM? $proc = @proc_open($this->options['-p'] . ' --version', array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE)); if ($proc === FALSE) { throw new \Exception('Cannot run PHP interpreter ' . $this->options['-p'] . '. Use -p option.'); } $output = stream_get_contents($pipes[1]); $error = stream_get_contents($pipes[2]); if (proc_close($proc)) { throw new \Exception("Unable to run '{$this->options['-p']}': " . preg_replace('#[\\r\\n ]+#', ' ', $error)); } if (preg_match('#HipHop VM#', $output)) { $this->interpreter = new HhvmPhpInterpreter($this->options['-p'], $args); } else { $this->interpreter = new ZendPhpInterpreter($this->options['-p'], $args); } if ($this->interpreter->getErrorOutput()) { echo Dumper::color('red', 'PHP startup error: ' . $this->interpreter->getErrorOutput()) . "\n"; if ($this->interpreter->isCgi()) { echo "(note that PHP CLI generates better error messages)\n"; } } }