Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

DevWebProDE
FlashNewz
DevWebPro










Getting A List Of Application Names In ColdFusion

By Raymond Camden
Expert Author
Article Date: 2007-12-21

Andy asks:

Is there a way to get a list of application names from all of the Application.cfc running on a server. I'm trying to dynamically build a server.applicationNameArray by just dropping a web app into the web tree. Thanks for your time.
Technically the answer to this is no, but there are two ways of doing this. The first way is to use the SeverMonitor API. There isn't a 'get a list of application names', but there is a method named getAllApplicationScopesMemoryUsed. This method returns the memory used by all application scopes on your server. The keys of the structure are your application names. Here is an example:

<cfset password = "poorspearsfamily">
<cfinvoke component="CFIDE.adminapi.administrator" method="login" adminpassword="#password#" returnVariable="result">

<cfinvoke component="CFIDE.adminapi.servermonitoring" method="getAllApplicationScopesMemoryUsed" returnVariable="ascopes">
<cfdump var="#ascopes#">


By the way, check out the memory usage for the model-glue app:

The Model-Glue app is the one in red. Model-Glue is so good it gives your server RAM. Yeah, that's it.

So the second solution is a bit of an hack, but has been around for a while. If you define an application w/o a name, the Application scope for that unnamed application will contain a bunch of junk, including a pointer to all the applications on your server. Consider this code:

<cfapplication>
<cfloop item="k" collection="#application#">
   <cfif isStruct(application[k]) and structKeyExists(application[k], "applicationname")>
    <cfdump var="#application[k]#" label="#k#">
   </cfif>
</cfloop>


This will dump each Application and all it's variables. Note the CFIF and how I check to see if the variable is an application scope. Not perfect, but in my test with both code blocks, it returned the same thing. (Well, the second code block didn't show the blank key for the unnamed application scope like the first one did.)

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



DevWebProDE is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal