ColdFusion Muse

Threads Not Terminating on ColdFusion 8.0.0

Over the past few days on CF Talk Ian Skinner has been struggling tuning an application that makes use of CFTHREAD. In his application a process spawns threads for creating report files. Ian Reports that the process would spawn the threads, but the threads themselves would neither complete gracefully nor respond to a "terminate" action (<cfthread action="terminate" ...>). No suggestions from the muse or anyone else seemed to help. Finally he upgraded to ColdFusion 8.0.1 and the problem appears to be resolved. Threads complete gracefully without hanging around.

Nothing in the 8.0.1 release notes raises any red flags with me that would indicate why updated to 8.0.1 resolved the issue. I suspect that something very specific about his JVM was causing it. Still, it's nice to know if you run into this ticklish issue there is a way around it.

CFCs, the Variables Scope, and the Application Scope

It's pretty common to use the application scope to cache components. If your component is a collection of methods or data access functions it's often faster to put them into the application scope than it is to create an instance with each request. Now you probably know that you should quality all of the variables in a function with the "var" key word. This insures that the variable exists inside the "scope" of the function call. This allows multiple function calls to be made to the same instance without one set of variables over writing the other.

One of the areas where this can be difficult to manage is when using a ColdFusion tag that creates its own scope. Take CFHTTP as an example.


New Coldfusion Podcast

Here's a quick public service announcement for all the muse readers. Apparently Coldfusion Weekly (a popular podcast) is ending its run. To pick up the slack, community member and CF Guru Brian Meloche has started a new podcast called CF Conversations. His first release is a round table discussion with Rick Mason, Adam Haskell, Aaron West, and Jeff Coughlin. There is also an i Tunes link.

Case Insensitive Form Field Names on Submit

Recently on CF Talk Bobby Hartsfield presented an interesting problem. A vendor required a submission of data as an XML packet. Since the data all came from a form post Bobby wanted to simply loop through the form fields to build his XML file. Each of the form field names would become a node in his XML doc. Sounds simple right?

Actually there is a problem with this approach. XML is typically case sensitive. If the vendor uses all upper or all lower case that's not a problem because you could simply UCASE() or LCASE() the field names. But what if the XML node names need to be mixed-case? For example, what if a node name was AdminUserName? You could add a form element to the form called AdminUserName, but when it is posted Coldfusion turns it into all upper case - as in ADMINUSERNAME. It's too bad there is no way to access the original case of the form elements before ColdFusion intervened. As it turns out (and thanks to some nifty code from both Bobby and the very bright Barney Boisvert) there is a way....


Tips on CF Script

From a reference on an email list I stumbled onto Pete Freitag's cheat sheet for CFSCRIPT and I thought it was worth mentioning. I use Cfscript for any largish block of logic. With the advent of CFC's it has become even more useful. I think the inline commenting is more readable and the syntax translates to other languages with a few modifications. To Pete's tips I would add the following:


List Delimiters and Coldfusion Magic

Here is one of those finicky nuances that might surprise you about Coldfusion. Many languages have list functions or something similar to list functions. In many of these languages there is some version of split or splitf that allows you to specify any string as a delimiter regardless of length. This might lead you to believe that you can use a multi-character string as a delimiter in list functions in Coldfusion. Not only is this not the case but the way delimiters behave can cause you to believe it is working when in fact it is not. Let me explain.


Running Multiple Instances of Homesite

This is an old tip that I had forgotten. Before I mention please know(as you should already know from the title) that this is a Homesite tip. It also applies to the old "Coldfusion studio" if that's your cup of tea. I know I know - I should always use CF eclipse. I have it and I use it but my trusty Homesite is an old friend and I can't seem to completely say goodby. Plus at 43 it's hard to teach an old dog new tricks :)


CFC Wrapper for 2D Barcodes Released

I have had a great many readers calling me and asking about the 2D barcode CFC mentioned in a recent post. You will be happy to know that it has been released. You can use this CFC to create 2D barcodes for printing and to read 2D barcodes containined in images. You can find the download link and read more about it on Ryan's blog. Keep in mind that the CFC is specific to CF8 and it uses a commercial (albeit inexpensive) Java library from Java4Less. Ryan and I would both be interested in any reviews or comments. If you end up using the tag we'd love to hear some follow-up on how it is being used.

Ask A Muse: Looking Up and IP Address By Host Name

Muse Reader Asks:
I need to resolve an internet address. For example, if I have, I'd like to be able to return the IP address.

One of the nice things about Coldfusion is the easy access to all that lovely Java stuff under the hood. Check out this network function listed at the basic syntax is:

    MyIp = getHostAddress(someurl);
That's it. Good luck and happy coding.

CSV Files and Coldfusion - a New Approach

Many times we have been tasked with working out a way for an ordinary user to "upload" data into a system. This task is fraught with peril because users are not well versed in the idea of "normalized" data. We've tried the Excel file approach. Excel gives the user so many neat options they can't resist adding formatting, charts, graphs and fiddling with the headers. Even with protected files, clever users find ways to make the data incomplete or unusable. We've also tried access. This is workable but it takes more setup and it requires extra expense on the part of the user (namely, they must have excel). Enter the famed low-tech "csv" or "comma separated value" file.


Ask-A-Muse: How Do I Use Client Variables?

Muse Reader Asks:
We have a client variables database that is currently storing over 1.5 million records. In the Coldfusion Administrator, client variables are set to purge every 90 days. I was thinking of purging every 7 to 30 days to reduce the number of database entries and hopefully improve performance. What are my options?

It's a good question. Performance depends on many thing including hardware, traffic, tuning, and capacity. Still, 1.5 million rows is a large table and as you might imagine it will perform less ably than a table with just a few hundred thousand rows. Let’s talk about these variables and how they are used.


Cfinclude vs Cfmodule and Other Things

Muse Reader Asks:
What is the difference between cfmodule, cfinclude? Which one should be used. We have two application.cfm file one at local folder and the other one at the common folder. Which application.cfm will be used when we try to execute Coldfusion template from local directory.

This is really 2 questions so let's take them one at a time. First, let's talk about the difference between Cfmodule and Cfinclude. The first thing to recognize is that that these 2 tags are quite different.


Ask-a-Muse: Why Don't My Images Display?

Muse Reader Asks:
"When I have subfolders, I have problems displaying images correctly. I tried setting a var called #dir_path# in my application.cfm file (this is actually to differentiate between dev and prod). Then I tried calling my includes and images like so:

<img src="#dir_path#/images/banner.jpg"/>
I know that with the cfinclude, I can't use a physical path, but even if I use a physical path with my images, it doesn't work - I just get a little box with a red "x" in it where my image should be. I've asked another programmer (who is way better than me) about it, and he said he just doesn't use subfolders because of that problem.

First let me say that you may have overestimated your friends programming skills. There is a fundamental difference between using cfinclude and displaying an image. the difference is that one of them has to do with Coldfusion and the other one simply doesn't have anything to do with Coldfusion. Let's review what happens when you load a coldfusion page with an image in it.


Ask A Muse: Cfinclude Versus Cffile

Muse Reader Asks:
"I am trying to use cfinclude to insert a txt file. But if the txt file has html / of cf code in it, i do not want it to be functional. can the txt file be read as a string?"

You know I love the easy ones. Your problem is misunderstanding the proper use of cfinclude. This tag passes the contents of the included file to the CF parser for execution. It's designed to compile into run time code. What you are trying to do is simply insert the contents of a file into the output buffer (the stuff that goes back to the browser). For that you can use cffile. Cffile will read the contents of your file into a variable - which you may then output onto the page. Here's an example.


<h4>output the contents of myfile</h4>


Notice the use of the expandPath() function. Unlike cfinclude which takes a relative Coldfusion path, cffile needs an absolute path. It needs something that looks like c:\inetpub\wwwroot\blah.txt (or maybe /var/home/www-data/blah.txt on a linux server). ExpandPath( ) is one of those can't-live-without-it functions that allows you to insert the path in a relative fashion.

In your question you indicated that you did not want the HTML to be "functional". I'm not sure what you mean by this - but I suspect you meant that you want the HTML to display on the page like "

" instead of like "this". For that you will need the htmleditformat( ) function as in...
I hope this helps.

Java Based Directory List

This is a follow post to my previous post on cfdirectory as a bottleneck. A helpful muse reader of that post named Daniel Gracia sent me some Java code that builds a directory list. The code itself is a call to the core io.File class. It takes a directory path and returns an array of files and folders mixed (with the folders identified with a period). His claim was that it performed faster than Cfdirectory. His claim is 100% true, but there are some nuances to it. I ran a few tests and here is what I found.


More Entries

Blog provided and hosted by CF Webtools. Blog Sofware by Ray Camden.