Multiple copies of files on every visit/refresh
| Project: | ImageCache |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Have imagecache running with Drupal 5.1 build, with 5.x-1.x-dev (and also tried 5.x-1.1 build) of imagecache. Took a bit of tweaking, but I've got imagecache working beautifully for my needs, but with one rather interesting glitch (at least I hope this isn't intended behavior). Every time it processes an imagecache URL, it creates another copy of the processed file rather than using one that already exists. So, on the first visit it creates "picture.jpg" and on every following visit or refresh it creates "picture_0.jpg" then "picture_1.jpg" and so on and so on. Is there some logic that it should be using to figure out that it has already processed this file and just use the existing that is getting stuck in my installation? This is running on IIS6/PHP5, and the folders it's using have full security control to all users. The CCK type is able to remove the master image and an imagecache flush on that preset works fine, removing that preset folder and all the multiple copies of the files in it.

#1
Sounds more like Clean URLs are not setup on your server. If your using IIS, you'll need to find an alternative to mod_rewrite, which I don't think is included in IIS.
Clean URLs are required because of the way imagecache works:
First request: file does not exist and Drupal passes the path to imagecache. Imagecache creates the image and saves it at that location.
Second request: the file exists at that location and Drupal is never loaded, the file is immediately returned.
For this to work, clean URLs are required. The request path MUST be files/imagecache/path/to/file.gif, not ?q=files/imagecache/path/to/file.gif. Otherwise you get that repeating behavior you are describing.
#2
Good grief. Yep, that was the issue. The fix wasn't fun, though. I did some investigating of rewrite on IIS, and came to the conclusion that the only methods worth using were the 3rd party ones that cost a good chunk of money (and I was gonna be using this on more servers/sites down the line, and didn't wanna face this kinda licensing per server as the good ones seem to charge). So, I FINALLY forced myself to get Apache2 setup on the server (I've gotten tired over time of the open source community ignoring IIS support almost completely for everything). This is now officially one heck of a fun server in terms of configuration. It's a Windows 2003 x64 server, running MySQL5 x64, PHP5 x64 and now Apache2 x64. And, having not been particularly familiar with setting up and running Apache, it took a couple hours to figure out what I was doing to setup the half dozen sites or so I was previous running under IIS6 on the Apache2 server. Never mind the fun of tracking down yet another x64 build of one of these projects (Apache, PHP and MySQL have x64 builds out there, but you have to hunt for 'em - thankfully I was already running the x64 builds of PHP & MySQL, so I didn't have to figure 'em all out at once). Then came the fun of getting the clean URLs to work, which took another hour of tweaking conf and htaccess files and rewrite modules and settings. After all this fun, it's working perfectly. So thanks, quicksketch, for the absolutely correct answer that sent me down this winding road... ;-)
I've seen a couple others commenting elsewhere about having problems with clean urls on Apache2/Windows. If you have stumbled upon this thread trying to figure that out, contact me. I might be able to give some samples that work for me.
#3
This patch (http://drupal.org/node/121401) should help with the ambiguity of this problem. Yes, IIS has sad support for rewriting URLs. But without a major change to the functionality of imagecache (basically a different module), it will always require URL rewriting.
#4
I got the same issue on Apache with version 5.x-1.2. Even when I'm loading the new file directly in the browser like www.example.com/files/imagecache/140x95/files/avisbilleder/2007/04/24/20... it generates a new image every time I reload. I've tried messing arounf with both the serverdirectives and the permission-settings.
Have you got any idea of what I'm doing wrong?
Best,
/Johs.
#5
Using mod_rewrite under IIS on Win2003, I seemed to need to send ALL imagecache image requests to the module. In the end I used the following rewrite rule, and modified the module (see attached patch for v.5.x-1.2) to first check whether the image had already been created, and skip the generation code if this was the case (just returning the already-generated file).
RewriteRule ^/(files/imagecache/.*)$ /index.php?q=$1 [l]
Perhaps this will be useful to other people who aren't in a position to switch to Apache. Note that the rewrite rule should precede any more general rules you are using for images.
#6
Thanks for the patch, though it cannot be applied to the project it serves as a work-around for IIS based users. By using the method you describe, there is little actual "caching" of images done. The generation is skipped but Drupal is still bootstrapped, a huge additional load on the server for no particular reason.
If you have mod_rewrite (or equivalent) available on your IIS server, this patch shouldn't be necessary. The concept is that Drupal is only called to handle the request if the file doesn't exist. If the file exists, mod_rewrite immediately returns the file and Drupal doesn't do anything.
#7
I am also running ISAPI_rewrite on IIS and it appears that it does not support a "file exists" type of flag like mod_rewrite for apache does using the "-f" flag. I am looking at using mod_rewrite for IIS instead of ISAPI_rewrite simply because it appears to support the -f flag according to this http://www.micronovae.com/ModRewrite/ref/RewriteCond.html. Is anyone using this successfully with imagecache?
#8
Yes, I'm pretty sure that micronovae IIS mod-rewrite supports this, but I'm having a heck of a time getting it working. I've instead used the beta of Helicon's ISAPI-rewrite which is working as expected only generating the image once and calling from cache.
#9
Yes, I'm pretty sure that micronovae IIS mod-rewrite supports this, but I'm having a heck of a time getting it working. I've instead used the beta of Helicon's ISAPI-rewrite which is working as expected only generating the image once and calling from cache.
#10
I'm also having the same issue using an Apache server and I already have Clean URLs enabled. The comment I'm replying to is marked "closed" (#4) but it isn't clear what is needed to fix this on Apache servers.
Any help is appreciated.
#11
open a new issue with directions to reproduce it, if clean urls does not resolve the problem...
You can also experiment with imagecache 2.x if your server does not support clean urls. I wouldn't suggest it on production sites just yet.