Cffile errors on slow machines

We do a lot of file management and custom version control for our clients and one of the things that give a lot of errors on CF 7 is the cffile tag. The tag is by itself is fine. But if you do multiple cffile operations after another, sometimes when the server is a bit slow you can get some none helping error messages. One that I personally had to debug was an issue in a "Image Gallery" that we've build for a client. Sometimes without a foreseen reason, the server would throw an error when the user deletes a image from a gallery. Nothing special you would say and it isn't anything special, but when you delete an image from the system, the user will delete 2 images (1 large and 1 thumbnail) and a record from a db.

The issue couldn't be recreated on our development server, but when the user told that the app runs on a shared server with x amount of other sites which he didn't control, the problem became a bit more obvious. There is nothing wrong with using shared hosting servers for small websites and apps which is the case for this client, but the down side of it is that you never know if someone else is hogging up the server with bad written code.

The error the client every now and then got was something like this:

ColdFusion could not delete the file "C:\xxxx\galleries\xxxxxxxx-xxxx-xxxx-0A99B271238CD62C\thumbs\New_Flamenco_3242434.JPG" for an unknown reason.

Because the system first deletes the big file and after that the small file, it must has something to do with Coldfusion not beeing ready with the first file when we try to delete the second file. We also tried to switch the deletion by first deleting the thumbnail and then the big file. That brought down the amount of errors, but that didn't made the error dissapear for good. So to let coldfusion wait for a few moments before deleting the second file we've put in a litle piece of Java into it. First delete the big file, wait a moment and then delete the second.

<!--- Delete small file first, thumbnail --->
<cffile action="delete" file="#thumbnailFile#" />
<!--- Let Coldfusion wait a bit --->
<cfset createObject("java", "java.lang.Thread").sleep(JavaCast("int", 4000))>
<!--- Delete the large file --->
<cffile action="delete" file="#sourceFile#" />

Any comments on other/better solutions for these kind of situations are more then welcome!

Back in business!

You probably seen the blog on mikemedia.eu/blog or on wantonline.com/blog in the past. We're closing that URL and start a fresh empty blog on this domain, mikeblog.eu.

Everybody from MikeMedia.eu (and some of our clients and partners) will post their thoughts, issues and tips on this blog. Some valuable tips from the old blog will be reposted here as well to make sure those tips will stay in our search results.

The design needs to be applied, but that will be done in the next couple of weeks (everyone is working hard on MikeSite 1.0 and MikeMini 1.5 releases at the moment!). By the time those releases are done, we should have some nice tips about YUI, Adobe AIR, Flex, Coldfusion and many more products & services.

Any questions? We could help you out if we have some time left and if it's an interesting issue.

BlogCFC was created by Raymond Camden. | Contact Blog Owner | All rights reserved | Copyright 2007 - 2012 MikeMedia.eu (Mike.nl BV)