Skip to content

Instantly share code, notes, and snippets.

@apinstein
Last active August 29, 2015 14:06
Show Gist options
  • Save apinstein/a2f1568863582e462239 to your computer and use it in GitHub Desktop.
Save apinstein/a2f1568863582e462239 to your computer and use it in GitHub Desktop.
php shutdown hook to generate curl request of the current request
<?php
register_shutdown_function(function() {
$f = '/tmp/last-request-' . microtime(true) . '.sh';
$rawData = json_decode(file_get_contents("php://input"));
$url = $_SERVER['REDIRECT_SCRIPT_URI'];
$requestData = http_build_query($_REQUEST);
$postData = NULL;
if ($_SERVER['REQUEST_METHOD'] === 'GET')
{
$url .= "?{$requestData}";
}
else
{
$postData = "-d '{$requestData}'";
}
file_put_contents($f, "
curl {$postData} '{$url}'
");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment