class PhpProcess

PhpProcess runs a PHP script in an independent process.

$p = new PhpProcess('<?php echo "foo"; ?>'); $p->run(); print $p->getOutput()."\n";

@author Fabien Potencier <fabien@symfony.com>

@api

Hierarchy

Expanded class hierarchy of PhpProcess

File

drupal/core/vendor/symfony/process/Symfony/Component/Process/PhpProcess.php, line 25

Namespace

Symfony\Component\Process
View source
class PhpProcess extends Process {
  private $executableFinder;

  /**
   * Constructor.
   *
   * @param string  $script  The PHP script to run (as a string)
   * @param string  $cwd     The working directory
   * @param array   $env     The environment variables
   * @param integer $timeout The timeout in seconds
   * @param array   $options An array of options for proc_open
   *
   * @api
   */
  public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array()) {
    parent::__construct(null, $cwd, $env, $script, $timeout, $options);
    $this->executableFinder = new PhpExecutableFinder();
  }

  /**
   * Sets the path to the PHP binary to use.
   *
   * @api
   */
  public function setPhpBinary($php) {
    $this
      ->setCommandLine($php);
  }

  /**
   * Runs the process.
   *
   * @param Closure|string|array $callback A PHP callback to run whenever there is some
   *                                       output available on STDOUT or STDERR
   *
   * @return integer The exit status code
   *
   * @api
   */
  public function run($callback = null) {
    if (null === $this
      ->getCommandLine()) {
      if (false === ($php = $this->executableFinder
        ->find())) {
        throw new \RuntimeException('Unable to find the PHP executable.');
      }
      $this
        ->setCommandLine($php);
    }
    return parent::run($callback);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpProcess::$executableFinder private property
PhpProcess::run public function Runs the process. Overrides Process::run
PhpProcess::setPhpBinary public function Sets the path to the PHP binary to use.
PhpProcess::__construct public function Constructor. Overrides Process::__construct
Process::$commandline private property
Process::$cwd private property
Process::$enhanceWindowsCompatibility private property
Process::$env private property
Process::$exitcode private property
Process::$exitCodes public static property Exit codes translation table.
Process::$fallbackExitcode private property
Process::$fileHandles private property
Process::$options private property
Process::$pipes private property
Process::$process private property
Process::$processInformation private property
Process::$readBytes private property
Process::$status private property
Process::$stderr private property
Process::$stdin private property
Process::$stdout private property
Process::$timeout private property
Process::addErrorOutput public function
Process::addOutput public function
Process::buildCallback protected function Builds up the callback used by wait().
Process::ERR constant
Process::getCommandLine public function
Process::getEnhanceWindowsCompatibility public function
Process::getEnv public function
Process::getErrorOutput public function Returns the current error output of the process (STDERR).
Process::getExitCode public function Returns the exit code returned by the process.
Process::getExitCodeText public function Returns a string representation for the exit code returned by the process.
Process::getOptions public function
Process::getOutput public function Returns the current output of the process (STDOUT).
Process::getStdin public function
Process::getStopSignal public function Returns the number of the signal that caused the child process to stop its execution
Process::getTermSignal public function Returns the number of the signal that caused the child process to terminate its execution.
Process::getTimeout public function
Process::getWorkingDirectory public function
Process::hasBeenSignaled public function Returns true if the child process has been terminated by an uncaught signal.
Process::hasBeenStopped public function Returns true if the child process has been stopped by a signal.
Process::isRunning public function Checks if the process is currently running.
Process::isSuccessful public function Checks if the process ended successfully.
Process::OUT constant
Process::processFileHandles private function Handles the windows file handles fallbacks
Process::setCommandLine public function
Process::setEnhanceWindowsCompatibility public function
Process::setEnv public function
Process::setOptions public function
Process::setStdin public function
Process::setTimeout public function Sets the process timeout.
Process::setWorkingDirectory public function
Process::start public function Starts the process and returns after sending the STDIN.
Process::STATUS_READY constant
Process::STATUS_STARTED constant
Process::STATUS_TERMINATED constant
Process::STDERR constant
Process::STDIN constant
Process::STDOUT constant
Process::stop public function Stops the process.
Process::updateErrorOutput protected function
Process::updateOutput protected function
Process::updateStatus protected function Updates the status of the process.
Process::wait public function Waits for the process to terminate.
Process::__destruct public function