scratch – Blame information for rev 126

Subversion Repositories:
Rev:
Rev Author Line No. Line
126 office 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 namespace Symfony\Component\Process;
13  
14 use Symfony\Component\Process\Exception\RuntimeException;
15  
16 /**
17 * PhpProcess runs a PHP script in an independent process.
18 *
19 * $p = new PhpProcess('<?php echo "foo"; ?>');
20 * $p->run();
21 * print $p->getOutput()."\n";
22 *
23 * @author Fabien Potencier <fabien@symfony.com>
24 */
25 class PhpProcess extends Process
26 {
27 /**
28 * Constructor.
29 *
30 * @param string $script The PHP script to run (as a string)
31 * @param string|null $cwd The working directory or null to use the working dir of the current PHP process
32 * @param array|null $env The environment variables or null to use the same environment as the current PHP process
33 * @param int $timeout The timeout in seconds
34 * @param array $options An array of options for proc_open
35 */
36 public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = null)
37 {
38 $executableFinder = new PhpExecutableFinder();
39 if (false === $php = $executableFinder->find(false)) {
40 $php = null;
41 } else {
42 $php = array_merge(array($php), $executableFinder->findArguments());
43 }
44 if ('phpdbg' === PHP_SAPI) {
45 $file = tempnam(sys_get_temp_dir(), 'dbg');
46 file_put_contents($file, $script);
47 register_shutdown_function('unlink', $file);
48 $php[] = $file;
49 $script = null;
50 }
51 if (null !== $options) {
52 @trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since version 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
53 }
54  
55 parent::__construct($php, $cwd, $env, $script, $timeout, $options);
56 }
57  
58 /**
59 * Sets the path to the PHP binary to use.
60 */
61 public function setPhpBinary($php)
62 {
63 $this->setCommandLine($php);
64 }
65  
66 /**
67 * {@inheritdoc}
68 */
69 public function start(callable $callback = null/*, array $env = array()*/)
70 {
71 if (null === $this->getCommandLine()) {
72 throw new RuntimeException('Unable to find the PHP executable.');
73 }
74 $env = 1 < func_num_args() ? func_get_arg(1) : null;
75  
76 parent::start($callback, $env);
77 }
78 }