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:


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.

5 responses to “Executing Code On Server Startup”

  1. Sid Wing Avatar
    Sid Wing

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

  2. Paul Avatar

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

  3. Esref Atak Avatar
    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.

  4. Esref Atak Avatar
    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~1INTERN~1IEXPLORE.EXE "http://localhost/runonstart.cfm"
    Windows automatically runs your web page when Windows start.

  5. David McGuigan Avatar
    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.

Leave a Reply