Making sure that your ColdFusion applications are uniquely named is crucial to proper application performance. If you have two ColdFusion applications that accidentally have the same name on the same instance, you'll get all kinds of weird, unexpected problems - variables not existing, wrong file paths, missing components, seemingly nonsensical settings. As such, it is very important that you pick unique application names. To make this decision easy (coming up with unique names requires too much thinking), I tend to use a combination of the hash() and getCurrentTemplatePath() functions in my Application.cfc
<cfcomponent output="false" hint="I define the application settings and event handlers."> <!--- Define the application. By using the current template path, we can ensure that our application name completely unique across the entire server. By using the hash() function, we make the name more friendly. ---> <cfset this.name = hash( getCurrentTemplatePath() ) /> <cffunction name="onRequest" access="public" returntype="void" output="true" hint="I execute the current request."> <!--- Debug the application name. ---> Current Template Path:<br /> #getCurrentTemplatePath()#<br /> <br /> Hash Of Template Path:<br /> #hash( getCurrentTemplatePath() )#<br /> </cffunction> </cfcomponent>
As you can see, the name of my application is a hash of the Application.cfc file path. Running this page gives us the following OnRequest() event handler output:
Current Template Path:
Hash Of Template Path:
The latter of the two outputs is what our application name becomes. Now, this might seem completely unreadable and meaningless to you; but, remember - you don't have to read it at all; the application name is used to associate your application with the ColdFusion memory space (including things like the APPLICATION scope and CFLogin functionality). As such, the uniqueness of the application name is of more importance than its meaningfulness to you.
By getting into the habit of using this approach to ColdFusion application name creation, I have found that I never have to worry about forgetting to properly name my application again. Since the getCurrentTemplatePath() function returns a value unique to the current Application.cfc file, the chances that its hash() will collide with another hash() are extremely small.
I know that a lot of you are already doing this in your ColdFusion applications; but, I just wanted to whip together this quick post so that I could refer back to it if it every came up in a conversation or in another Coldfusion blog post. Also, if you aren't doing this, I would definitely recommend it - it has made my life a lot easier to debug.
Want to use code from this post? Check out the license.