checkPortIsAvailable example

->getIterator();
    $this->copyCodebase($iterator);
    /** @var \Symfony\Component\Process\Process[] $processes */
    $processes = [];
    $count = 15;
    for ($i = 0; $i <= $count$i++) {
      $port = $this->findAvailablePort();
      $this->assertArrayNotHasKey($port$processes, 'Port ' . $port . ' was already in use by a process.');
      $processes[$port] = $this->instantiateServer($port);
      $this->assertNotEmpty($processes[$port]);
      $this->assertTrue($processes[$port]->isRunning(), 'Process on port ' . $port . ' is not still running.');
      $this->assertFalse($this->checkPortIsAvailable($port));
    }

    // Clean up after ourselves.     foreach ($processes as $process) {
      $process->stop();
    }
  }

  /** * @covers ::standUpServer */
  
if (file_exists($working_path . DIRECTORY_SEPARATOR . '.ht.router.php')) {
      $server[] = $working_path . DIRECTORY_SEPARATOR . '.ht.router.php';
    }
    $ps = new Process($server$working_path);
    $ps->setIdleTimeout(30)
      ->setTimeout(30)
      ->start();
    // Wait until the web server has started. It is started if the port is no     // longer available.     for ($i = 0; $i < 50; $i++) {
      usleep(100000);
      if (!$this->checkPortIsAvailable($port)) {
        return $ps;
      }
    }

    throw new \RuntimeException(sprintf("Unable to start the web server.\nCMD: %s \nCODE: %d\nSTATUS: %s\nOUTPUT:\n%s\n\nERROR OUTPUT:\n%s", $ps->getCommandLine()$ps->getExitCode()$ps->getStatus()$ps->getOutput()$ps->getErrorOutput()));
  }

  /** * Stop the HTTP server, zero out all necessary variables. */
  protected function stopServer() {
    
Home | Imprint | This part of the site doesn't use cookies.