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'];
|
$tag = $_GET['tag'];
|
||||||
$santag = checkTag($tag);
|
$santag = checkTag($tag);
|
||||||
$tempfile = "/tmp/konasub/$selectedServer/$santag.xml";
|
$cacheName = "konasub_$selectedServer_$santag";
|
||||||
$selfUrl = "https://shimatta.de/konasub/?tag=$tag";
|
$selfUrl = "https://shimatta.de/konasub/?tag=$tag";
|
||||||
|
|
||||||
dbg ("Tag: \"$tag\" ($santag, $tempfile)\n");
|
dbg ("Tag: \"$tag\" ($santag, $tempfile)\n");
|
||||||
mkdir ("/tmp/konasub/$selectedServer");
|
|
||||||
|
|
||||||
// Configure server urls and meta data
|
// Configure server urls and meta data
|
||||||
$svr['konachan']['imgBase'] = "http://konachan.com/post/show/";
|
$svr['konachan']['imgBase'] = "http://konachan.com/post/show/";
|
||||||
@ -52,20 +52,14 @@
|
|||||||
$svr['konachan']['link'] = "http://konachan.com/post?tags=" . urlencode($tag);
|
$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'[^\\\"]*)\\\"" . " .*\\/>/";
|
$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 ($data = apcu_fetch($cacheName)) {
|
||||||
if ((time() - filemtime($tempfile)) > $refreshTime) {
|
dbg (" -> Loading cached data...");
|
||||||
$cacheFile = fopen($tempfile, "w");
|
|
||||||
dbg (" -> Retrieving file...");
|
|
||||||
$data = file_get_contents($svr[$selectedServer]['url']);
|
|
||||||
fwrite($cacheFile, $data);
|
|
||||||
flush();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cacheFile = fopen($tempfile, "r");
|
dbg (" -> Retrieving latest data from server...");
|
||||||
dbg (" -> Loading cached file...");
|
$data = file_get_contents($svr[$selectedServer]['url']);
|
||||||
$data = fread($cacheFile,filesize($tempfile));
|
apcu_store($cacheName, $data, $refreshTime);
|
||||||
}
|
}
|
||||||
fclose($cacheFile);
|
|
||||||
|
|
||||||
dbg("BEGIN XML:\n");
|
dbg("BEGIN XML:\n");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user