Blog

22Jun
2009
Executing Code On Server Startup

ColdFusion can execute code when an application starts and ends, when a session starts and ends, when a request starts and ends, and more. But what if you need to execute code when a server starts up? Granted, this is not a common use case, but when needed, we've had to use onApplicationStart for this, probably doing something like:

view plain print about
1<cfif not IsDefined("SERVER.myVar")>
2...
3</cfif>

ColdFusion Centaur adds the ability to define code to be executed onServerStart.

By default this is a method named onServerStart in server.cfc. But, actually, it can be in any ColdFusion Component, including an Application.cfc. In ColdFusion Administrator you can point to the CFC and method to be invoked, and ColdFusion will execute the code on server start-up before processing any requests.

Related Blog Entries

Comments (5)



  • Sid Wing

    Ah the wonders of Centaur! I have a USE for this particular feature, too!

    #1Posted by Sid Wing | Jun 22, 2009, 08:03 AM
  • Paul

    This release is shaping up to have some nifty features. Good on Adobe for implementing features that, you know, matter to developers.

    #2Posted by Paul | Jun 22, 2009, 10:55 AM
  • Esref Atak

    I suggest, create a CFML tamplate. Add a IF condition, if there is no defined "application.check" then run the code. Add this page to Scheduled Tasks ind ColdFusion. Schedule increment is 10sn

    Simple and effectivly.

  • Esref Atak

    Another way is could be:

    Add a Scheduled Task to Windows. Select the IE from list in wizard. Finish the wizard. Type to Run textbox like that:

    C:\PROGRA~1\INTERN~1\IEXPLORE.EXE "http://localhost/runonstart.cfm";

    Windows automatically runs your web page when Windows start.

  • David McGuigan

    Ben! Don't downplay the benefits and power of onServerStart. A lot of apps take an initial hit on the first request while all of the onApplicationStart initialization runs. onServerStart is the perfect opportunity to initialize all of the apps on the server and get the first-serve overhead out of the way so the first user doesn't feel it. It's Michael Jackson bad.

    #5Posted by David McGuigan | Jun 26, 2009, 03:21 AM