Changed caching to APCU (fixed #1)
This commit is contained in:
parent
ccd7c65d16
commit
a04cdd7703
20
index.php
20
index.php
@ -39,10 +39,10 @@
|
||||
|
||||
$tag = $_GET['tag'];
|
||||
$santag = checkTag($tag);
|
||||
$tempfile = "/tmp/konasub/$selectedServer/$santag.xml";
|
||||
$cacheName = "konasub_$selectedServer_$santag";
|
||||
$selfUrl = "https://shimatta.de/konasub/?tag=$tag";
|
||||
|
||||
dbg ("Tag: \"$tag\" ($santag, $tempfile)\n");
|
||||
mkdir ("/tmp/konasub/$selectedServer");
|
||||
|
||||
// Configure server urls and meta data
|
||||
$svr['konachan']['imgBase'] = "http://konachan.com/post/show/";
|
||||
@ -52,20 +52,14 @@
|
||||
$svr['konachan']['link'] = "http://konachan.com/post?tags=" . urlencode($tag);
|
||||
$svr['konachan']['re'] = "/<post.* author=\\\"(?'author'[^\\ ]*)\\\".* created_at=\\\"(?'created_at'[^\\ ]*)\\\".* id=\\\"(?'id'[^\\ ]*)\\\".* jpeg_url=\\\"(?'jpeg_url'[^\\ ]*)\\\".* tags=\\\"(?'tags'[^\\\"]*)\\\"" . " .*\\/>/";
|
||||
|
||||
dbg ("File mtime delta: " . (time() - filemtime($tempfile)) . " (of $refreshTime)");
|
||||
if ((time() - filemtime($tempfile)) > $refreshTime) {
|
||||
$cacheFile = fopen($tempfile, "w");
|
||||
dbg (" -> Retrieving file...");
|
||||
$data = file_get_contents($svr[$selectedServer]['url']);
|
||||
fwrite($cacheFile, $data);
|
||||
flush();
|
||||
if ($data = apcu_fetch($cacheName)) {
|
||||
dbg (" -> Loading cached data...");
|
||||
}
|
||||
else {
|
||||
$cacheFile = fopen($tempfile, "r");
|
||||
dbg (" -> Loading cached file...");
|
||||
$data = fread($cacheFile,filesize($tempfile));
|
||||
dbg (" -> Retrieving latest data from server...");
|
||||
$data = file_get_contents($svr[$selectedServer]['url']);
|
||||
apcu_store($cacheName, $data, $refreshTime);
|
||||
}
|
||||
fclose($cacheFile);
|
||||
|
||||
dbg("BEGIN XML:\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user