Yes. Done. End of post. See ya. Ok - bad joke. Let me be a bit more verbose. Earlier today a user on Twitter asked if it was possible to manually run your ColdFusion's OnServerStart component. This is the component you register within your CF Admin to run on server startup, as I've done here:
Here is the CFC I wrote, which just does a simple log:
public function onServerStart() {
writelog(file="application", text="Starting up at #now()#");
}
}
component {
And the answer is - as I said above - yes. You can call it from any other CFM/CFC you wish:
<cfset myServer = new myServer()>
<cfset myServer.onServerStart()>
The only thing to keep in mind is that - much like calling Application.cfc methods manually - your call will not be automatically single threaded as a "real" onServerStart call is. I have to say that I've yet to use this feature in production yet. Anyone else? Also - I want to give props to Daria for answering this on Stack Overflow as well.
Archived Comments
I use the server scope a lot to share what we'd normally think of as application scoped variables across the entire site. This is because of previous choices about how our site's application.cfm files were set up. So i use onServerStart() to initialize all the cached server scope data and use the method above when I need to reinitialize.
This is not the solution for everyone and i'd warn against using the server scope unless you have complete control over your ColdFusion server.
Great site and great articles! Will link you in the ColdFusion part of my site:
http://www.leolol.com/drupa...