Skip to content

Instantly share code, notes, and snippets.

@wowo
Created August 28, 2015 12:52
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 wowo/791bddbfa896e3566e95 to your computer and use it in GitHub Desktop.
Save wowo/791bddbfa896e3566e95 to your computer and use it in GitHub Desktop.
Simple api to capture and test API callbacks
<?php
$log = __DIR__ . '/api.log';
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$payload = json_decode(file_get_contents('php://input'), true) ?: $_POST;
file_put_contents(
$log,
sprintf(
"[%s] (%s - %s) %s\n",
(new \DateTime())->format('Y-m-d H:i:s'),
$_SERVER['REMOTE_ADDR'],
gethostbyaddr($_SERVER['REMOTE_ADDR']),
var_export($payload, 1)
),
FILE_APPEND
);
exit('OK' . PHP_EOL);
} else {
if (file_exists($log)) {
echo '<pre>' . file_get_contents($log);
} else {
echo 'No log file under ' . $log;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment