Skip to content

Instantly share code, notes, and snippets.

@prufrock
Last active August 29, 2018 02:51
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 prufrock/3173348948a7e0654d2c57c3ef31e3df to your computer and use it in GitHub Desktop.
Save prufrock/3173348948a7e0654d2c57c3ef31e3df to your computer and use it in GitHub Desktop.
An HTTP server that prints back your request in PHP. Put this file in a folder, open a terminal in the folder and type: "php -S localhost:979"` and whizz bang pow! You'll have a server you can use to test your requests!
<?php
# Inspired by https://stackoverflow.com/a/49007601
function stdout($arg) {
if (is_object($arg) || is_array($arg) || is_resource($arg)) {
$output = print_r($arg, true);
} else {
$output = (string) $arg;
}
file_put_contents('php://stdout', $output . \PHP_EOL);
}
stdout('Look Sharp! Request Received!');
stdout($_SERVER);
stdout(getallheaders());
$headers = getallheaders();
if ($headers['Content-Type'] == 'application/json') {
stdout(json_encode(json_decode(file_get_contents('php://input')), JSON_PRETTY_PRINT));
} else {
stdout(file_get_contents('php://input'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment