Skip to content

Instantly share code, notes, and snippets.

@Maff-
Created January 14, 2013 17:00
Show Gist options
  • Save Maff-/4531518 to your computer and use it in GitHub Desktop.
Save Maff-/4531518 to your computer and use it in GitHub Desktop.
<?php
$ttl = 60*60*2; // 2 hours
parse_str($_SERVER['QUERY_STRING'], $q);
$out = array();
if (!empty($q['r']) && function_exists('apc_fetch')) {
if (!apc_exists('test-' . $q['r'])) {
header("Status: 404 Not Found");
die;
} else {
$out = apc_fetch('test-' . $q['r']);
}
} else {
ksort($_SERVER);
reset($_SERVER);
$out = array(
'_SERVER' => array_filter($_SERVER,
function($val) use (&$_SERVER) {
$key = key($_SERVER);
next($_SERVER);
return preg_match("/^REQUEST|CONTENT|REMOTE|SERVER|QUERY|HTTP/", $key);
}
),
'_GET' => $_GET,
'_POST' => $_POST,
'_COOKIE' => $_COOKIE,
);
if (function_exists('apc_store')) {
$uid = base_convert(microtime(true), 10, 36);
$out['SAVED_REQUEST'] = 'http://' . $_SERVER['HTTP_HOST'] . '/?r=' . $uid;
if (!apc_store('test-'.$uid, $out, $ttl)) {
unset($out['request_url']);
} else {
header('X-Request-Id: ' . $uid);
}
}
}
if (!empty($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json') {
header('Content-Type: application/json');
echo json_encode($out);
} else {
header('Content-Type: text/plain');
var_export($out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment