WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site with 9000 posts and those posts have external images and they are not stored on my server. These posts have thumbs that show on the homepage.

My problem is this: whenever someone visits the site, many text files get created in the cache directory via thumb.php and they go up to 9000 if all my posts are featured. There are only text files in the cache directory, and they are not cleared any way automatically. How do I make them get cleared automatically? GoDaddy doesn't allow more than 1024 files to be stored in a single directory and therefore they issued a warning to me this morning. And I need to get those cache folders cleared automatically.

I have ('FILE_CACHE_ENABLED', TRUE); btw if this has anything to do with this issue. I didn't even touch thumb.php. My other sites work well and nothing is stored in their cache.

I have also checked TimThumb's configuration page online. I've tried Timthumb Vulnerability Scanner, I have no caching plugin installed, I've also tried to create a cron job schedule, but on GoDaddy I could only manage to clear the directory at certain times, not for when a certain size is reached. GoDaddy allows up to 10 cron jobs and up to 5 minutes to function between cron jobs. During those 5 minutes, more than 1024 text files are created, which doesn't work for me. But I believe there must be something that can be done to clean the cache automatically?

Thumbs are hosted elsewhere already. Cache only creates text files to identify, but doesn't clean them. Can anyone help me with this pretty please? Please explain what I need to do step by step as I have a very limited knowledge on this.

share|improve this question

closed as off topic by Chip Bennett, brasofilo, kaiser, s_ha_dum, Milo Feb 6 '13 at 16:15

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

TimThumb is a third-party PHP script, and is not WordPress-specific. – Chip Bennett Feb 6 '13 at 13:46
Thanks Chip. Very helpful that was. I don't see any other questions about timthumb here at all. correct. – Argus Feb 6 '13 at 13:57
We even got a tag timthumb dedicated to those questions... Please don't get sarcastic when you didn't even get the basic concept of the site or refuse to do a real search. – kaiser Feb 6 '13 at 14:11
How is your question specific to WordPress? (Please note: our FAQ explicitly states that just because an issue occurs in the context of WordPress does not mean that the issue is inherently WordPress-related, and therefore not inherently in-scope for WPSE.) You're using a non-WordPress script to generate a non-WordPress file cache, and hitting a non-WordPress host file limit. Try to have TimThumb cache 9000 images using a different CMS, and you'll have the identical problem, with the identical (non-WordPress-related) solution. – Chip Bennett Feb 6 '13 at 14:16
I believe I have mentioned what I have done to solve this problem. This is the point where my knowledge is insufficient and therefore I'm asking it as a question tagged with timthumb. – Argus Feb 6 '13 at 14:16
up vote 0 down vote accepted

Check or add the following two config settings:

define('FILE_CACHE_TIME_BETWEEN_CLEANS', 80000); // 8 seconds = automatic removal of files
define('FILE_CACHE_MAX_FILE_AGE', 20000); // 2 seconds = max. age of file before removed


Maybe using something like this code snippet in your thumb.php or as a stand-alone script executed by cron can take care of the issue. It'll delete files in your cache directory that are older than 30 seconds.


$dir = '/path/to/cache/';

if ( is_dir( $dir ) ) {
    if ( $handle = opendir( $dir ) ) {
        while ( ( $file = readdir( $handle ) ) !== false ) {
            if ( time() - filemtime( $dir . $file ) >= 1800 ) {
                unlink( $dir . $file );
        closedir( $handle );

share|improve this answer
Thank you stealthyninja for a serious reply. I have tried what you suggested and it didn't solve the issue. I still have .txt files generated in my cache folder to define the external images, and they are not cleaned in any way, but they should be actually. What can be wrong with this? Any suggestions? – Argus Feb 6 '13 at 15:09
My first suspicion was that the cache files created by TimThumb might have different permissions (or even a different owner) which could cause the cache clearing routines to silently fail. If, however, my above script works, I'm wrong and TimThumb is just being lame for some other reason. – stealthyninja Feb 6 '13 at 22:17
Thank you again stealthyninja. The script above didn't work for me. I have updated timthumb and I still get the same problem. I don't know what's causing this. The permission setting for the folder is 777, the standart txt timthumb files created by timthumb have permission 600. But that's the standart I guess. Any other suggestion you got? – Argus Feb 6 '13 at 22:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.