Browse Source

Changed caching to APCU (fixed #1)

master
Markus Koch 6 years ago
parent
commit
a04cdd7703
  1. 28
      index.php

28
index.php

@ -37,12 +37,12 @@
else
$selectedServer = "konachan";
$tag = $_GET['tag'];
$santag = checkTag($tag);
$tempfile = "/tmp/konasub/$selectedServer/$santag.xml";
$selfUrl = "https://shimatta.de/konasub/?tag=$tag";
$tag = $_GET['tag'];
$santag = checkTag($tag);
$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));
else {
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…
Cancel
Save