Not yet rated

Problem

Code needs to be executed every time the server starts up.

Solution

ColdFusion 9 introduced the onServerStart method into application framework in a new ColdFusion component, Server.cfc.

Detailed explanation

Having code run each time the server starts can be used for a variety of reasons but should be reserved for application independent tasks such as server wide logging.  ColdFusion 9 introduced the onServerStart method that, if implemented will run each time the server starts.  The method is the only method in the new ColdFusion component Server.cfc.  Unless an alternate location is  specified in the ColdFusion administrator the ColdFusion server will look for Server.cfc in the webroot.

The following code will run when the server starts up and set a server wide variable that holds the data and time the server started.

<cfcomponent>
<cffunction name="onServerStart">
<cfset Server.StartUpDateTime = Now() />
</cffunction>
</cfcomponent>

With the addition of the onServerStart method applications can now handle server wide setup easily and efficiently.

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes