summaryrefslogtreecommitdiff
path: root/init.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-10-18 16:45:29 +0300
committerAndrew Dolgov <[email protected]>2020-10-18 16:45:29 +0300
commit3c18ed3b4ed78564fd1c739bc468e65dcf7f607e (patch)
tree22a36f1588caa4594c7d302b27e41018fab8eb8c /init.php
parent06c38e1745e7fb450d392b607c0e5f5fb170fd9e (diff)
prevent repeated failures if image failes to process (OOM, etc)
Diffstat (limited to 'init.php')
-rwxr-xr-xinit.php15
1 files changed, 14 insertions, 1 deletions
diff --git a/init.php b/init.php
index fdf99ae..e163028 100755
--- a/init.php
+++ b/init.php
@@ -284,8 +284,17 @@ class Af_Img_Phash extends Plugin {
_debug("phash: downloading and calculating hash...");
+ $cached_file = sha1($src);
+ $cached_file_flag = "$cached_file.phash-flag";
+
if ($this->cache->isWritable()) {
- $cached_file = sha1($src);
+
+ if ($this->cache->exists($cached_file_flag)) {
+ _debug("phash: $cached_file_flag exists, looks like we failed on this URL before; skipping.");
+ continue;
+ }
+
+ $this->cache->touch($cached_file_flag);
if (!$this->cache->exists($cached_file)) {
$data = fetch_file_contents(array("url" => $src, "max_size" => MAX_CACHE_FILE_SIZE));
@@ -316,6 +325,10 @@ class Af_Img_Phash extends Plugin {
_debug("phash: calculated perceptual hash: $hash");
+ // we managed to process this image, it should be safe to remove the flag now
+ if ($this->cache->isWritable() && $this->cache->exists($cached_file_flag))
+ unlink($this->cache->getFullPath($cached_file_flag));
+
if ($hash) {
$hash = base_convert($hash, 16, 10);