Created
April 25, 2017 05:08
-
-
Save ctrl-freak/738b8997952d6cdaf24481dd7c937c96 to your computer and use it in GitHub Desktop.
EVE Simple CREST Cache
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
| <? | |
| ini_set('max_execution_time', 60); | |
| set_time_limit(60); | |
| error_reporting(0); | |
| $options = array( | |
| 'base_url' => 'https://public-crest.eveonline.com', | |
| 'cache_expiry' => 1200 | |
| ) | |
| $filename = 'cache-'.md5($_SERVER['REQUEST_URI']); | |
| if (!file_exists($filename)) { | |
| $request = file_get_contents($options['base_url'].$_SERVER['REQUEST_URI']); | |
| if ($request !== FALSE) { | |
| file_put_contents($filename, $request); | |
| } | |
| } | |
| if (file_exists($filename)) { | |
| closeOutput(file_get_contents($filename)); | |
| } | |
| if (filemtime($filename) < (time()-$options['cache_expire'] | |
| $request = file_get_contents($options['base_url'].$_SERVER['REQUEST_URI']); | |
| if ($request !== FALSE) { | |
| file_put_contents($filename, $request); | |
| } | |
| } | |
| //print(var_export($_SERVER, true)); | |
| function closeOutput($stringToOutput){ | |
| set_time_limit(0); | |
| ignore_user_abort(true); | |
| header("Connection: close\r\n"); | |
| header("Content-Encoding: none\r\n"); | |
| ob_start(); | |
| // Blank response, store as empty JSON object | |
| if ($stringToOutput == '') { | |
| $stringToOutput = '{}'; | |
| } | |
| echo $stringToOutput; | |
| $size = ob_get_length(); | |
| header("Content-Length: $size",TRUE); | |
| ob_end_flush(); | |
| ob_flush(); | |
| flush(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment