Skip to main content
Inspiring
December 7, 2011
Answered

Adding variable in onApplicationStart

  • December 7, 2011
  • 1 reply
  • 769 views

Hi,

When we add a new variable in Application.cfc under the method onApplicationStart the variable doesn't seem to be visible until we restart the application. But as I am a beginner I am not sure what Restarting an Application means? Would restarting the Coldfusion Server from services.msc be enough?


Thanks

Adil Shoukat

This topic has been closed for replies.
Correct answer Owainnorth

Restarting an Application is just restarting the website - yes restarting the entire service will work, but is complete overkill.

OnApplicationStart fires the first time your website is accessed in a specified period of time (set with this.ApplicationTimeout) - once that time has elapsed with no visitors, your onApplicationEnd() method fires and the application is removed from memory. The next time it's then accessed, onApplicationStart is called and the site is loaded back into memory.

You're not seeing onApplicationStart fire because you're developing the website, so it's not been idle. During development, I do something like this in your onRequestStart() method:

<cfif structKeyExists(url, 'restart') >

  <cfset onApplicationStart() />

</cfif>

That way all I have to do is put ?restart at the end of any URL, and it'll restart the website. Much quicker and more efficient than restarting CF.

1 reply

Owainnorth
OwainnorthCorrect answer
Inspiring
December 7, 2011

Restarting an Application is just restarting the website - yes restarting the entire service will work, but is complete overkill.

OnApplicationStart fires the first time your website is accessed in a specified period of time (set with this.ApplicationTimeout) - once that time has elapsed with no visitors, your onApplicationEnd() method fires and the application is removed from memory. The next time it's then accessed, onApplicationStart is called and the site is loaded back into memory.

You're not seeing onApplicationStart fire because you're developing the website, so it's not been idle. During development, I do something like this in your onRequestStart() method:

<cfif structKeyExists(url, 'restart') >

  <cfset onApplicationStart() />

</cfif>

That way all I have to do is put ?restart at the end of any URL, and it'll restart the website. Much quicker and more efficient than restarting CF.

Inspiring
December 7, 2011

Thanks a lot Owain North. Adding a variable in onApplicationStart had been a nightmare for me. But you've given a nice idea. You made my life easy
Thanks again

Owainnorth
Inspiring
December 7, 2011

No problem at all