How can I find what machine/server my code is running on?
You can determine the name of the server your code is running on, as well as the ColdFusion instance that is executing it. This is very useful if you have code that you only want to execute in a development environment, or to easily tell which server in a cluster is executing your request.
To retrieve the physical server name:
To retrieve the ColdFusion instance:
Some sample code for a fairly common setup:
###right(host,1)# box in the cluster, by the #cfserv# instance of CF.
-->
<cfelse><!-- This code was executed on the dev or test box named
#host#, by the #cfserv# instance of CF. --></cfif>
Of course, you'll probably want to obfuscate that a bit, maybe a switch/case statement renaming them to something recognizable without giving away any of your host or instance names.
Another excellent use of this code is for a generic error handler that emails you when something goes wrong:
#dateformat(NOW(),'m/d/yy')# at #timeformat(NOW(),'h:mm:ss tt')#">
<cfdump var="#cfcatch#" format="text">
<cfdump var="#cgi#" format="text">
... and so on
</cfmail>
This question was written by J.C. Overgaard.
It was last updated on July 3, 2008 at 9:29:38 AM EDT.
CFML Referenced
<cfif>
Now()
<cfelse>
<cfmail>
Categories
Comments
There are no comments for this entry.