An error occured fetching image 解决WordPress程序出现”A TimThumb error has occured”报错问题

本人解决办法 把缓存文件夹清空重新生成即可解决

下面是网摘

昨天有网友在网站中有使用WPCOS、WPOSS这类对象存储插件的时候发现无论安装哪款插件虽然图片能够被传到对象存储中,或者是在传图片的时候有出现”A TimThumb error has occured”这样的错误。老蒋特意让这网友将错误贴出来:

A TimThumb error has occured
The following error(s) occured:
An error occured fetching image.

 

从报错信息中可以看到他当前的WordPress主题中是有TimThumb图片自定义功能的。常见的是因为目录权限,比如当前他的主题中是否有cache文件夹,需要授权777才可以。参考”解决timthumb.php管理WordPress缩略图不显示问题”。

 

同时在”解决WPDX主题timthumb.php无法调出外部图片缩略图的问题”也有解决遇到,需要在对应的配置文件中授权外链接图片地址权限,这样才可以展示图片。

Emmm,这个竟然折腾了几个小时。本来计划将网站的静态文件访问顺序调为

网站 —->CDN—-COS

感觉这样一弄 CDN 和COS之间回源要收费,CDN 本身流量也要收费,就是传说中的双向收费。想了一下CDN还是算了吧,但是自己之前买的一年的CDN啊!哭。。。。

一顿瞎改,替换COS链接为CDN链接,巴拉巴拉一堆,然后更换ECC证书等一些列操作之后首页缩略图挂了。

然后我以为是设置COS防盗链设置出了问题,我取消防盗链还是会出现错误。

Timthumb我也没怎么修改源码,但是还是出现了错误:

An error occured fetching image.

看源码在这个位置:

protected function tryServerCache(){ //写日志,记录将读取服务端缓存,级别3 $this->debug(3, “Trying server cache”); //如果缓存文件存在 if(file_exists($this->cachefile)){ //写日志,记录缓存文件存在 $this->debug(3, “Cachefile {$this->cachefile} exists”); //如果请求的是外部图片地址 if($this->isURL){ //写日志,记录这是一次外部请求,级别3 $this->debug(3, “This is an external request, so checking if the cachefile is empty which means the request failed previously.”); //如果缓存文件的大小小于1,也就是说是一个无效的缓存文件 if(filesize($this->cachefile) < 1){ //写日志,记录这是一个空的缓存文件,级别3 $this->debug(3, “Found an empty cachefile indicating a failed earlier request. Checking how old it is.”); //如果已到了配置文件中清理无效缓存的时间 if(time() – @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){ //写日志,记录这次删除操作,级别3 $this->debug(3, “File is older than ” . WAIT_BETWEEN_FETCH_ERRORS . ” seconds. Deleting and returning false so app can try and load file.”); //删除此缓存文件 @unlink($this->cachefile); //返回假,说明没有读取到服务端缓存 return false; //否则,空的缓存文件说明上次请求失败,所以要写错误记录 } else { //写日志,记录空的缓存文件依然有效,级别3 $this->debug(3, “Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.”); //设置404错误 $this->set404(); //设置错误信息 $this->error(“An error occured fetching image.”); //返回假代表没有得到缓存 return false; } } //否则就是正确的缓存文件 } else { //写日志,记录将要直接读取缓存文件,级别3 $this->debug(3, “Trying to serve cachefile {$this->cachefile}”); } //如果输出图像缓存成功 if($this->serveCacheFile()){ //写日志,记录缓存文件信息,级别3 $this->debug(3, “Succesfully served cachefile {$this->cachefile}”); return true; //如果不成功 } else { //写日志,记录错误信息,级别3 $this->debug(3, “Failed to serve cachefile {$this->cachefile} – Deleting it from cache.”); //删除此无效缓存,以便下次请求能重新创建 @unlink($this->cachefile); //同样返回真,因为在serverCacheFile已经记录了错误信息 return true; } } }

 

Solve the problem of “A TimThumb error has occured” in the WordPress program. My solution is to empty the cache folder and regenerate it. The following is a net summary. Yesterday, some netizens used WPCOS, WPOSS and other object storage plugins in the website. Which plug-in is installed, although the image can be transferred to the object storage, or an error such as “A TimThumb error has occured” appears when uploading the image. Old Jiang specifically asked this netizen to post the error: From the error message, you can see that his current WordPress theme has a TimThumb picture customization function. Commonly, it is because of directory permissions, such as whether there is a cache folder in the current theme, it needs to be authorized 777. Refer to “Solve the problem of not displaying thumbnails of WordPress in timthumb.php management”.
At the same time, “Solve the problem that WPDX theme timthumb.php can not call up external picture thumbnails” has also solved the problem. It is necessary to authorize the external link picture address permission in the corresponding configuration file, so that the picture can be displayed.
Emmm, this has been tossing for a few hours. The original plan was to adjust the static file access order of the website to the website. It feels like that, if the CDN and COS return to the source, the CDN itself will also be charged, which is the legendary two-way charging. After thinking about the CDN, let’s forget it, but I bought a year’s CDN before! Cry… After a bit of change, I replaced the COS link with a CDN link, a bunch of Barabara, and then replaced the ECC certificate. After a series of operations, the home page thumbnails hung up.
Then I thought it was a problem with the COS anti-leech setting, and I would still get an error when I cancel the anti-leech.
I didn’t modify the source code much, but there was still an error: Look at the source code at this location: write log, record will read server-side cache, level 3 $this->debug(3, “Trying server cache”); //if The cache file exists if(file_exists($this->cachefile)){ //Write the log and record that the cache file exists $this->debug(3, “Cachefile {$this->cachefile} exists”); //If requested Is the external image address if($this->isURL){ //Write log, record that this is an external request, level 3 $this->debug(3, “This is an external request, so checking if the cachefile is empty which means the request failed previously.”); //If the size of the cache file is less than 1, that is to say it is an invalid cache file if(filesize($this->cachefile) <1){ //Write a log and record this An empty cache file, level 3 $this->debug(3, “Found an empty cachefile indicating a failed earlier request. Checking how old it is.”); //If it’s time to clean up the invalid cache in the configuration file if (time()-@filemtime($this->cachefile)> WAIT_BETWEEN_FETCH_ERRORS){ //Write a log to record this delete operation, level 3 $this->debug(3, “File is older than “. WAIT_BETWEEN_FETCH_ERRORS.” seconds . Deleting and returning false so app can try and load file.”); //Delete this cache file @unlink($this->cachefile); //Return false, indicating that the server cache has not been read return false; // Otherwise, the empty cache file means that the last request failed, so write an error record} else {//Write the log, the empty cache file is still valid, level 3 $this->debug(3, “Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.”); //Set 404 error$this->set404(); //Set error message$this->error(“An error occured fetching image.”); //Returning false means not getting the cache return false;}} //Otherwise it is the correct cache file} else {//Write the log, record that the cache file will be read directly, level 3 $this->debug( 3, “Trying to serve cachefile {$this->cachefile}”);} //If the output image is cached successfully if($this->serveCacheFile()){ //write log, record cache file information, level 3 $this ->debug(3, “Succesfully served cachefile {$this->cachefile}”); return true; //If unsuccessful} else {//Write log, record error information, level 3 $this->debug(3, “Failed to serve cachefile {$this->cachefile}-Deleting it from cache.”); //Delete this invalid cache so that the next request can be recreated @unlink($this->cachefile); //The same returns true , Because the error message has been recorded in serverCacheFile

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注