EmbeddedServer::stopAndWait PHP Method

stopAndWait() public method

Stop the embedded server and wait until it actually exited.
public stopAndWait ( ) : boolean
return boolean true if the server stopped, otherwise false.
    function stopAndWait()
    {
        $running = $this->isRunning();
        if ($running) {
            // Stop the server.
            $success = $this->stop();
            if (!$success) {
                return false;
            }
            // Give the server time to actually go down.
            // But not more than 10 second.
            $logFile = $this->_getLogFileName();
            file_put_contents($logFile, 'Waiting for server to stop ', FILE_APPEND);
            $maxWait = 10;
            while ($this->isRunning() && $maxWait > 0) {
                file_put_contents($logFile, '.', FILE_APPEND);
                sleep(1);
                $maxWait--;
            }
            if ($maxWait == 0) {
                file_put_contents($logFile, ' timeout' . PHP_EOL, FILE_APPEND);
                return false;
            } else {
                file_put_contents($logFile, PHP_EOL, FILE_APPEND);
            }
        }
        return true;
    }

Usage Example

Esempio n. 1
0
 /**
  * @covers EmbeddedServer
  */
 public function testStartStopIsRunning()
 {
     // Check whether the server is currently running.
     $running = $this->embeddedServer->isRunning();
     if ($running) {
         // If the server is running we stop it, then start it.
         // Stop the server.
         self::assertTrue($this->embeddedServer->stopAndWait());
         // Restart the server.
         self::assertTrue($this->embeddedServer->start());
         self::assertTrue($this->embeddedServer->isRunning());
     } else {
         // If the server is stopped, we start it, then stop it.
         // Start the server.
         self::assertTrue($this->embeddedServer->start());
         self::assertTrue($this->embeddedServer->isRunning());
         // Stop the server.
         self::assertTrue($this->embeddedServer->stopAndWait());
     }
 }
All Usage Examples Of EmbeddedServer::stopAndWait