Last active
August 29, 2018 02:51
-
-
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!
This file contains hidden or 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
<?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