Skip to content

Instantly share code, notes, and snippets.

@fjarrett
Created August 30, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarrett/c800cb0abf8af95c6c1f3cd7a2381011 to your computer and use it in GitHub Desktop.
Save fjarrett/c800cb0abf8af95c6c1f3cd7a2381011 to your computer and use it in GitHub Desktop.
Use the Requests lib to wait for the built-in PHP server to start up
<?php
$process = new Process( sprintf( 'php -S localhost:8080 -t %s', __DIR__ ) );
$process->start();
$start = time();
// Wait for the server to start up (5 seconds max).
do {
try {
Requests::get( 'http://localhost:8080' );
} catch ( Requests_Exception $e ) {
continue;
}
break;
} while ( time() - $start < 5 );
Requests::get( 'http://localhost:8080/test.php' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment