Local cached images stops working after refresh
-
Hey,
So I’m this awesome plugin using on my website, with the option for local caching images for better mobile performance.
For some reason, after I clear the local cache, it works, the thumbnails shows corretly. But after I refresh the page, the same URL returns an error 500 for the images.
I do not know what else to do. I have no idea what’s wrong.
Thanks,
ShirkitThe page I need help with: [log in to see the link]
-
any errors in the php errorlog shirkit ?
Nope, the best I have is this, after enabling debug logging. No errors thrown at WordPress, Nginx or PHP-FPM level I could find.
2019/05/28 10:46:58 [notice] 2219#2219: *14 "(\?add-to-cart=|/cart/|/my-account/|/checkout/|/shop/checkout/|/store/checkout/|/customer-dashboard/|/addons/|/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)" matches "/wp-content/plugins/wp-youtube-lyte/lyteThumbs.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FREsDbKZ17kU%2Fhqdefault.jpg", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /wp-content/plugins/wp-youtube-lyte/lyteThumbs.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FREsDbKZ17kU%2Fhqdefault.jpg HTTP/2.0", host: "curso.orquidariobahia.com.br" 2019/05/28 10:46:58 [notice] 2219#2219: *14 "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|edd_items_in_cart|woocommerce_items_in_cart|woocommerce_cart_hash|woocommerce_recently_viewed|wc_session_cookie_HASH|wp_woocommerce_session_|wptouch_switch_toogle" does not match "__tawkuuid=e::curso.orquidariobahia.com.br::BVERLtZk/qIb3Lvfu18eE3e8NDFacgs8AmWUs1xwmtz6rSo21XlypsDu/i6y/r4G::2; TawkConnectionTime=0", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /wp-content/plugins/wp-youtube-lyte/lyteThumbs.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FREsDbKZ17kU%2Fhqdefault.jpg HTTP/2.0", host: "curso.orquidariobahia.com.br" 2019/05/28 10:46:58 [notice] 2219#2219: *14 "image/webp" does not match "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /wp-content/plugins/wp-youtube-lyte/lyteThumbs.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FREsDbKZ17kU%2Fhqdefault.jpg HTTP/2.0", host: "curso.orquidariobahia.com.br" 2019/05/28 10:46:58 [notice] 2219#2219: *14 "(\?add-to-cart=|/cart/|/my-account/|/checkout/|/shop/checkout/|/store/checkout/|/customer-dashboard/|/addons/|/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)" does not match "/favicon.ico", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /favicon.ico HTTP/2.0", host: "curso.orquidariobahia.com.br" 2019/05/28 10:46:58 [notice] 2219#2219: *14 "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|edd_items_in_cart|woocommerce_items_in_cart|woocommerce_cart_hash|woocommerce_recently_viewed|wc_session_cookie_HASH|wp_woocommerce_session_|wptouch_switch_toogle" does not match "__tawkuuid=e::curso.orquidariobahia.com.br::BVERLtZk/qIb3Lvfu18eE3e8NDFacgs8AmWUs1xwmtz6rSo21XlypsDu/i6y/r4G::2; TawkConnectionTime=0", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /favicon.ico HTTP/2.0", host: "curso.orquidariobahia.com.br" 2019/05/28 10:46:58 [notice] 2219#2219: *14 "image/webp" matches "image/webp,*/*", client: 177.98.231.120, server: curso.orquidariobahia.com.br, request: "GET /favicon.ico HTTP/2.0", host: "curso.orquidariobahia.com.br"the only thing I can think of is filesystem permissions for the PHP process (it needs read/write to
wp-content/cache/lyteThumbsand it’s contents ?The files are there, as expected, and it does have permissions, and creating the files with regular permissions.
When I delete the files, the first time I reload the images, they are loaded. When I refresh the page, error 500 is thrown without any logging.
[11:20][root@digitalocean.atlantidastudios.com cache]# ls -l total 4 drwxrws--- 4 nginx nginx 62 Mar 28 20:06 autoptimize -rw-r--r-- 1 nginx nginx 47 Jan 24 10:38 cache-enabler-advcache-curso.orquidariobahia.com.br.json drwxr-sr-x 2 nginx nginx 24 May 28 11:19 lyteThumbs drwxrws--- 2 nginx nginx 6 Nov 19 2018 supercache [11:20][root@digitalocean.atlantidastudios.com cache]# cd lyteThumbs/ [11:20][root@digitalocean.atlantidastudios.com lyteThumbs]# ls -l total 4 -rw-r--r-- 1 nginx nginx 197 May 27 18:25 index.html [11:20][root@digitalocean.atlantidastudios.com lyteThumbs]# ls -l total 300 -rw-r--r-- 1 nginx nginx 13949 May 28 11:20 3e1d305402634def44a4fa0d9448c829.jpg -rw-r--r-- 1 nginx nginx 17225 May 28 11:20 7ae9dc43438ea79a78ff879eba4c7c80.jpg -rw-r--r-- 1 nginx nginx 25123 May 28 11:20 80dbfb68efd67bcc37757c80a94b1d29.jpg -rw-r--r-- 1 nginx nginx 9693 May 28 11:20 a89e4384bdef732a9f204c1d3e7ce192.jpg -rw-r--r-- 1 nginx nginx 14423 May 28 11:20 aaa92a4487579d596c856146fafcc4dc.jpg -rw-r--r-- 1 nginx nginx 18246 May 28 11:20 cadebfae36b9247068d31c2855969a0c.jpg -rw-r--r-- 1 nginx nginx 18899 May 28 11:20 d216bdb962c1344c59aedb7c50538841.jpg -rw-r--r-- 1 nginx nginx 19003 May 28 11:20 eaa4e29137055a5fb6c3014ea31864b0.jpg -rw-r--r-- 1 nginx nginx 145175 May 28 11:20 f3c9a9377df4193c9d4f612bcd74c414.jpg -rw-r--r-- 1 nginx nginx 197 May 27 18:25 index.html [11:20][root@digitalocean.atlantidastudios.com lyteThumbs]#well, for the first request, the image is not fetched from cache but straight from the YT API response.
so as it works the first time request and as you have cache files in lyteThumbs the 500 is thrown when trying to read from cache. but the permissions *look* OK.
but … I just looked and the thumbnails now seem to load OK??
That was because I cleared the cache. How can we check if LyteThumbs is fetching the right file locally? Or maybe the request is screwing this somehow, with the special characters?
by adding some debug-code. on line 81 of wp-content/plugins/wp-youtube-lyte/lyteThumbs.php you have
$localThumb = LYTE_CACHE_DIR . '/' . md5($origThumbURL) . ".jpg";right after that add
error_log('trying to fetch: '.$localThumb);and then watch the php errorlog for the output.
right before and after line 96 you could also add some debug output;
$thumbContents = file_get_contents( $localThumb );becomes
error_log('going to try to get thumbnail from cache'); $thumbContents = file_get_contents( $localThumb ); error_log('got thumbnail from cache');Ok, I found out that
mime_content_type()quietly shuts down without any warning or error being thrown, on line 95.Running PHP 7.2.18 on NGinx 1.17.0
hmmm … and what does
function_exists('mime_content_type');return?Interesting I think it’s returning false, since
function_exists('mime_content_type') === falseis returning1, butfunction_exists('mime_content_type') === trueisn’t returning anything.OK, I committed a potential fix here, could you test (you can download the entire plugin zip-file from Github here).
Yes, applying the patch did fix it. Thanks for your support! Love your Autoptimize, it’s just the best!
Thanks!
thanks for the confirmation, I’ll make sure this goes in the next release 🙂
The topic ‘Local cached images stops working after refresh’ is closed to new replies.