示例#1
0
 /** @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";
         }
     }
 }