-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from nategood/test-server
Introduces support for the baked in PHP HTTP Server in 5.4
- Loading branch information
Showing
4 changed files
with
78 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
$php_version = phpversion(); | ||
$php_major = floatval(substr($php_version, 0, 3)); | ||
|
||
if ($php_major < 5.4) { | ||
define('WITHOUT_SERVER', true); | ||
} else { | ||
// Command that starts the built-in web server | ||
$command = sprintf('php -S %s:%d -t %s >./server.log 2>&1 & echo $!', WEB_SERVER_HOST, WEB_SERVER_PORT, WEB_SERVER_DOCROOT); | ||
|
||
// Execute the command and store the process ID | ||
$output = array(); | ||
exec($command, $output, $exit_code); | ||
|
||
// sleep for a second to let server come up | ||
sleep(1); | ||
$pid = (int) $output[0]; | ||
|
||
// check server.log to see if it failed to start | ||
$server_logs = file_get_contents("./server.log"); | ||
if (strpos($server_logs, "Fail") !== false) { | ||
// server failed to start for some reason | ||
print "Failed to start server! Logs:" . PHP_EOL . PHP_EOL; | ||
print_r($server_logs); | ||
exit(1); | ||
} | ||
|
||
echo sprintf('%s - Web server started on %s:%d with PID %d', date('r'), WEB_SERVER_HOST, WEB_SERVER_PORT, $pid) . PHP_EOL; | ||
|
||
register_shutdown_function(function() { | ||
// cleanup after ourselves -- remove log file, shut down server | ||
global $pid; | ||
unlink("./server.log"); | ||
posix_kill($pid, SIGKILL); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo": "bar", "baz": false} |