This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Process/PhpProcess.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2010-04-17 13:49:58 +01:00
<?php
/*
2010-04-24 00:22:16 +01:00
* This file is part of the Symfony package.
2010-04-17 13:49:58 +01:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-04-17 13:49:58 +01:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
2012-08-30 20:25:16 +01:00
use Symfony\Component\Process\Exception\RuntimeException;
2010-04-17 13:49:58 +01:00
/**
* PhpProcess runs a PHP script in an independent process.
2010-04-17 13:49:58 +01:00
*
* $p = new PhpProcess('<?php echo "foo"; ?>');
* $p->run();
* print $p->getOutput()."\n";
*
* @author Fabien Potencier <fabien@symfony.com>
2011-03-24 08:13:58 +00:00
*
* @api
2010-04-17 13:49:58 +01:00
*/
class PhpProcess extends Process
{
private $executableFinder;
/**
* Constructor.
*
2014-11-30 13:33:44 +00:00
* @param string $script The PHP script to run (as a string)
* @param string $cwd The working directory
* @param array $env The environment variables
* @param int $timeout The timeout in seconds
* @param array $options An array of options for proc_open
2011-03-24 08:13:58 +00:00
*
* @api
*/
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
2010-04-17 13:49:58 +01:00
{
parent::__construct(null, $cwd, $env, $script, $timeout, $options);
$this->executableFinder = new PhpExecutableFinder();
2010-04-17 13:49:58 +01:00
}
/**
* Sets the path to the PHP binary to use.
2011-03-24 08:13:58 +00:00
*
* @api
*/
public function setPhpBinary($php)
{
2011-03-24 08:10:42 +00:00
$this->setCommandLine($php);
}
2010-04-17 13:49:58 +01:00
/**
* {@inheritdoc}
*/
public function start($callback = null)
2010-04-17 13:49:58 +01:00
{
2011-03-24 08:15:33 +00:00
if (null === $this->getCommandLine()) {
if (false === $php = $this->executableFinder->find()) {
2012-08-30 20:25:16 +01:00
throw new RuntimeException('Unable to find the PHP executable.');
}
$this->setCommandLine($php);
}
2010-04-17 13:49:58 +01:00
parent::start($callback);
2010-04-17 13:49:58 +01:00
}
}