diff options
author | Andrew Dolgov <[email protected]> | 2020-10-18 16:45:29 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2020-10-18 16:45:29 +0300 |
commit | 3c18ed3b4ed78564fd1c739bc468e65dcf7f607e (patch) | |
tree | 22a36f1588caa4594c7d302b27e41018fab8eb8c /init.php | |
parent | 06c38e1745e7fb450d392b607c0e5f5fb170fd9e (diff) |
prevent repeated failures if image failes to process (OOM, etc)
Diffstat (limited to 'init.php')
-rwxr-xr-x | init.php | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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); |