1 | <?php |
||
17 | class FastCGI extends AbstractAdapter |
||
18 | { |
||
19 | /** |
||
20 | * @var Client |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * @var Array of patterns matching php socket files |
||
26 | */ |
||
27 | protected $possibleSocketFilePatterns = [ |
||
28 | '/var/run/php*.sock', |
||
29 | '/var/run/php/*.sock' |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $host; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $chroot; |
||
41 | |||
42 | /** |
||
43 | * @param string $host 127.0.0.1:9000 or /var/run/php5-fpm.sock |
||
44 | * @param string $chroot |
||
45 | */ |
||
46 | 9 | public function __construct($host = null, $chroot = null) |
|
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | 3 | protected function doRun(Code $code) |
|
99 | |||
100 | 3 | protected function request(Code $code) |
|
101 | { |
||
102 | 3 | $file = $this->createTemporaryFile(); |
|
103 | 3 | $this->logger->info(sprintf('FastCGI: Dumped code to file: %s', $file)); |
|
104 | |||
105 | try { |
||
106 | 3 | $code->writeTo($file); |
|
107 | |||
108 | $environment = [ |
||
109 | 1 | 'SERVER_ADDR' => '127.0.0.1', |
|
110 | 1 | 'REMOTE_ADDR' => '127.0.0.1', |
|
111 | 1 | 'REMOTE_PORT' => '65000', |
|
112 | 1 | 'REQUEST_METHOD' => 'POST', |
|
113 | 1 | 'REQUEST_URI' => '/', |
|
114 | 1 | 'SCRIPT_FILENAME' => $this->getScriptFileName($file), |
|
115 | ]; |
||
116 | |||
117 | 1 | $this->logger->info(sprintf('FastCGI: Requesting FPM using socket: %s', $this->host)); |
|
118 | 1 | $response = $this->client->request($environment, ''); |
|
119 | 1 | $this->logger->debug(sprintf('FastCGI: Response: %s', json_encode($response))); |
|
120 | |||
121 | 1 | if (!@unlink($file)) { |
|
122 | $this->logger->debug(sprintf('FastCGI: Could not delete file: %s', $file)); |
||
123 | } |
||
124 | |||
125 | 1 | return $response; |
|
126 | 2 | } catch (\Exception $e) { |
|
127 | 2 | if (!@unlink($file)) { |
|
128 | 2 | $this->logger->debug(sprintf('FastCGI: Could not delete file: %s', $file)); |
|
129 | } |
||
130 | |||
131 | 2 | throw new \RuntimeException( |
|
132 | 2 | sprintf('FastCGI error: %s (%s)', $e->getMessage(), $this->host), |
|
133 | 2 | $e->getCode(), |
|
134 | $e |
||
135 | ); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @param string $file |
||
141 | * @return string |
||
142 | * @throws \RuntimeException |
||
143 | */ |
||
144 | 2 | protected function getScriptFileName($file) |
|
154 | } |
||
155 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.