| Conditions | 6 |
| Paths | 13 |
| Total Lines | 38 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | protected function batch(Input $input): ?string |
||
| 18 | { |
||
| 19 | \assert($input->isArray()); |
||
| 20 | |||
| 21 | $children = []; |
||
| 22 | $responses = []; |
||
| 23 | foreach ($input->data() as $request) { |
||
| 24 | $pair = \stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); |
||
| 25 | |||
| 26 | $pid = \pcntl_fork(); |
||
| 27 | |||
| 28 | if (0 === $pid) { |
||
| 29 | \fclose($pair[0]); |
||
| 30 | |||
| 31 | \fwrite($pair[1], $this->single(Input::fromSafeData($request)) . ''); |
||
| 32 | |||
| 33 | \fclose($pair[1]); |
||
| 34 | |||
| 35 | exit(0); |
||
| 36 | } |
||
| 37 | |||
| 38 | \fclose($pair[1]); |
||
| 39 | |||
| 40 | $children[$pid] = $pair[0]; |
||
| 41 | } |
||
| 42 | |||
| 43 | while (-1 !== $pid = \pcntl_wait($status)) { |
||
| 44 | $socket = $children[$pid]; |
||
| 45 | |||
| 46 | if ('' !== $response = \stream_get_contents($socket)) { |
||
| 47 | $responses[] = $response; |
||
| 48 | } |
||
| 49 | |||
| 50 | \fclose($socket); |
||
| 51 | } |
||
| 52 | |||
| 53 | return empty($responses) ? |
||
| 54 | null : \sprintf('[%s]', \implode(',', $responses)); |
||
| 55 | } |
||
| 57 |