You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

3 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Contracts\HttpClient\Test;
  11. use Symfony\Component\Process\PhpExecutableFinder;
  12. use Symfony\Component\Process\Process;
  13. class TestHttpServer
  14. {
  15. private static $process = [];
  16. public static function start(int $port = 8057)
  17. {
  18. if (isset(self::$process[$port])) {
  19. self::$process[$port]->stop();
  20. } else {
  21. register_shutdown_function(static function () use ($port) {
  22. self::$process[$port]->stop();
  23. });
  24. }
  25. $finder = new PhpExecutableFinder();
  26. $process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:'.$port]));
  27. $process->setWorkingDirectory(__DIR__.'/Fixtures/web');
  28. $process->start();
  29. self::$process[$port] = $process;
  30. do {
  31. usleep(50000);
  32. } while (!@fopen('http://127.0.0.1:'.$port, 'r'));
  33. return $process;
  34. }
  35. }