I suggest you ...

onServerStart

I would like to have a onServerStart() event, similar to onApplicationStart() but for server wide functions. There I could set global fucntions, variables and also start vital applications in a controlled fashion.

27 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    stefan.vesterlundstefan.vesterlund shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Bruce KirkpatrickBruce Kirkpatrick commented  ·   ·  Flag as inappropriate

        Michael told me in a group thread that you can use the event gateway features for this because it runs before any requests do. If you CFLOCK the server scope, you should be able to do all your startup routine. The exact code and documentation is something I'd have to locate if I do this though. Allow me to provide a code example of how to achieve this with just a simple application.cfm or cfc though:
        <cfif structkeyexists(server,'appinited') EQ false or (isDefined('zreset') and (zreset EQ 'server' or zreset EQ 'all'))>
        <cflock scope="server" type="exclusive" timeout="60">
        <cfif structkeyexists(server,'appinited') EQ false or zreset EQ 'server' or zreset EQ 'all'>
        <!--- init here --->
        </cfif>
        </cflock>
        </cfif>

        By having the same logic tests outside AND inside the lock, you guarantee that no 2 requests will do the heavy work at the same time. I've been using this for years with success. It does make logical sense to have an onServerStart function, but keep in mind that you can make one yourself right now and it will work with Application.cfc if you call the method manually in your component - I did this already. You might have more then one app using server scope, so I usually prefix my server variables with an app id string.

      • stefan.vesterlundstefan.vesterlund commented  ·   ·  Flag as inappropriate

        GX, as I see it I would put it in the Railo install package, a Server.cfc is not so far away from an Application.cfc

        The idea is to be able to give more than one application access to certain common data and/or functionality without having them all trying to initialize it at the same time when the server comes alive. Currently you need to do quite a bit of locking and checking before using common resources.

        This would also be very useful for virtual hosting since the applications could rely on the existence of certain object and certain data.

      • GXGX commented  ·   ·  Flag as inappropriate

        Interesting idea but where would you put it? onApplicationStart goes in application.cfc of relative application would you put this in one of any of the applications on the server? how would this impact shared virtual hosting? It sounds like you have a shared library and need a way to always include and call some basic init methods.

      Feedback and Knowledge Base