| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <fabien@symfony.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* PhpProcess runs a PHP script in an independent process. |
| 14 |
* |
| 15 |
* $p = new PhpProcess('<?php echo "foo"; ?>'); |
| 16 |
* $p->run(); |
| 17 |
* print $p->getOutput()."\n"; |
| 18 |
* |
| 19 |
* @author Fabien Potencier <fabien@symfony.com> |
| 20 |
* |
| 21 |
* @api |
| 22 |
*/ |
| 23 |
class Symfony_Process_PhpProcess extends Symfony_Process_Process |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Constructor. |
| 27 |
* |
| 28 |
* @param string $script The PHP script to run (as a string) |
| 29 |
* @param string $cwd The working directory |
| 30 |
* @param array $env The environment variables |
| 31 |
* @param int $timeout The timeout in seconds |
| 32 |
* @param array $options An array of options for proc_open |
| 33 |
* |
| 34 |
* @api |
| 35 |
*/ |
| 36 |
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array()) |
| 37 |
{ |
| 38 |
$executableFinder = new Symfony_Process_PhpExecutableFinder(); |
| 39 |
if (false === $php = $executableFinder->find()) { |
| 40 |
$php = null; |
| 41 |
} |
| 42 |
|
| 43 |
parent::__construct($php, $cwd, $env, $script, $timeout, $options); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Sets the path to the PHP binary to use. |
| 48 |
* |
| 49 |
* @api |
| 50 |
*/ |
| 51 |
public function setPhpBinary($php) |
| 52 |
{ |
| 53 |
$this->setCommandLine($php); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* {@inheritdoc} |
| 58 |
*/ |
| 59 |
public function start($callback = null) |
| 60 |
{ |
| 61 |
if (null === $this->getCommandLine()) { |
| 62 |
throw new Symfony_Process_Exception_RuntimeException('Unable to find the PHP executable.'); |
| 63 |
} |
| 64 |
|
| 65 |
parent::start($callback); |
| 66 |
} |
| 67 |
} |
| 68 |
|