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
|
|
|
*
|
2011-03-06 11:40:06 +00: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.
|
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
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
|
|
|
/**
|
2010-09-19 23:40:30 +01:00
|
|
|
* PhpProcess runs a PHP script in an independent process.
|
2010-04-17 13:49:58 +01:00
|
|
|
*
|
2010-12-20 09:30:59 +00:00
|
|
|
* $p = new PhpProcess('<?php echo "foo"; ?>');
|
|
|
|
* $p->run();
|
|
|
|
* print $p->getOutput()."\n";
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @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
|
|
|
|
{
|
2011-04-08 11:07:31 +01:00
|
|
|
private $executableFinder;
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param string $script The PHP script to run (as a string)
|
|
|
|
* @param string $cwd The working directory
|
|
|
|
* @param array $env The environment variables
|
2014-04-12 18:54:57 +01:00
|
|
|
* @param int $timeout The timeout in seconds
|
2010-05-06 12:25:53 +01:00
|
|
|
* @param array $options An array of options for proc_open
|
2011-03-24 08:13:58 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
|
2010-04-17 13:49:58 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
parent::__construct(null, $cwd, $env, $script, $timeout, $options);
|
2011-04-08 11:07:31 +01:00
|
|
|
|
|
|
|
$this->executableFinder = new PhpExecutableFinder();
|
2010-04-17 13:49:58 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets the path to the PHP binary to use.
|
2011-03-24 08:13:58 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setPhpBinary($php)
|
|
|
|
{
|
2011-03-24 08:10:42 +00:00
|
|
|
$this->setCommandLine($php);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-04-17 13:49:58 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2012-12-18 21:02:51 +00:00
|
|
|
* {@inheritdoc}
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2012-12-18 21:02:51 +00:00
|
|
|
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()) {
|
2011-04-26 14:18:21 +01:00
|
|
|
if (false === $php = $this->executableFinder->find()) {
|
2012-08-30 20:25:16 +01:00
|
|
|
throw new RuntimeException('Unable to find the PHP executable.');
|
2011-04-26 14:18:21 +01:00
|
|
|
}
|
|
|
|
$this->setCommandLine($php);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-04-17 13:49:58 +01:00
|
|
|
|
2013-01-08 19:11:30 +00:00
|
|
|
parent::start($callback);
|
2010-04-17 13:49:58 +01:00
|
|
|
}
|
|
|
|
}
|