| Conditions | 4 |
| Paths | 6 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 33 | public function start(): int |
||
| 34 | { |
||
| 35 | $this->port = $this->findFreePort(); |
||
| 36 | |||
| 37 | $command = \sprintf( |
||
| 38 | 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!', |
||
| 39 | $this->host, |
||
| 40 | $this->port, |
||
| 41 | $this->documentRoot |
||
| 42 | ); |
||
| 43 | |||
| 44 | \exec($command, $output); |
||
| 45 | |||
| 46 | $this->pid = (int)$output[0]; |
||
| 47 | |||
| 48 | $start = \microtime(true); |
||
| 49 | $connected = false; |
||
| 50 | |||
| 51 | while (\microtime(true) - $start <= self::SERVER_TIMEOUT_SECONDS) { |
||
| 52 | if ($this->canConnect()) { |
||
| 53 | $connected = true; |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | if (!$connected) { |
||
| 59 | $this->stop(); |
||
| 60 | throw new \RuntimeException('Timed out'); |
||
| 61 | } |
||
| 62 | |||
| 63 | return $this->port; |
||
| 64 | } |
||
| 97 |