Re: What event specifically triggers OnApplicationStart?
Ian Skinner - I owe you an apology. After studying the access logs from the web server, I can't say with 100% certainty but it looks like this happened because someone hit the web server using an IP address. They didn't use the password to force a call to OnApplicationStart so it must have been right after a server reboot. I've rewritten that code to be more robust. :-) ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343419 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
memory variables only timeout if they are not accessed the specified timeout period. every time anyone loads a page on your site, it accesses the application scope and their session scope, so the timeout is reset back to 0. An application will restart when ColdFusion restarts, when you reach the applicationTimeout, if you force a restart via code or via the CFADMIN/server monitor When you say you use cgi.server_name to determine which variables to use, are you being VERY explicity, as in the SERVER_NAME must match EXACTLY, or are you doing an if/else to say if its this then set as live else set as dev ? On Mon, Mar 28, 2011 at 6:25 PM, Dave Burns cft...@burnsorama.com wrote: In Application.cfc, I know that OnApplicationStart is called when an application starts. I'd like to define that better. From what I've read, this is when the first page is requested from an app (also possible are event gateways and Flash remoting but I'm not using either). So, if I say: this.applicationTimeout = CreateTimeSpan(1, 0, 0, 0); in my Application.cfc and a day goes by since calling OnApplicationStart, isn't it true that the server doesn't invoke my code on its own (like a cron job). It waits for a day to go by and then invokes OnApplicationStart on the next page request - even if that request is hours later? I'm asking because I'm trying to track down some odd behavior in a customer's app. The OnApplicationStart code looks at CGI.SERVER_NAME to determine which config file to load (production, staging, dev, etc.). Twice in the last 6 months, the production system starts to think it's a dev system. Are there cases where CGI.SERVER_NAME could be empty or undefined or... when OnApplicationStart is called? Can I trust that CGI var's are always set correctly in this scenario? ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343353 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
memory variables only timeout if they are not accessed the specified timeout period. every time anyone loads a page on your site, it accesses the application scope and their session scope, so the timeout is reset back to 0. An application will restart when ColdFusion restarts, when you reach the applicationTimeout, if you force a restart via code or via the CFADMIN/server monitor To confirm my understanding, are you saying that on a very busy site, it's possible that OnApplicationStart might never run again once the app has started? (server admin and restarts aside.) Since the app is running fine for months and then all of a sudden switches configs, something else then must trigger a call to OnApplicationStart but with a screwy environment. (I'm going to add logging to track this down but I can't predict when the problem might happen again.) When you say you use cgi.server_name to determine which variables to use, are you being VERY explicity, as in the SERVER_NAME must match EXACTLY, or are you doing an if/else to say if its this then set as live else set as dev? My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production I can tell from a diagnostic page I have that configName's value ended up being dev. Fixing the problem is as easy as forcing a call to OnApplicationStart by hitting a special URL. Which makes me wonder under what circumstances OnApplicationStart can be called without CGI being set properly. Strange. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343357 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
To confirm my understanding, are you saying that on a very busy site, it's possible that OnApplicationStart might never run again once the app has started? (server admin and restarts aside.) That's exactly correct. Since the app is running fine for months and then all of a sudden switches configs, something else then must trigger a call to OnApplicationStart but with a screwy environment. (I'm going to add logging to track this down but I can't predict when the problem might happen again.) It's entirely possible that (a) the server is stopping and restarting, which will cause all applications to stop, or (b) there's an explicit call to onApplicationStart somewhere within your code - this is actually pretty common. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343358 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: What event specifically triggers OnApplicationStart?
On said diagnostic page, what is the value of CGI.SERVER_NAME and CGI.HTTP_HOST when the configName's value is dev? -Original Message- From: Dave Burns [mailto:cft...@burnsorama.com] Sent: Monday, March 28, 2011 1:10 PM To: cf-talk Subject: Re: What event specifically triggers OnApplicationStart? memory variables only timeout if they are not accessed the specified timeout period. every time anyone loads a page on your site, it accesses the application scope and their session scope, so the timeout is reset back to 0. An application will restart when ColdFusion restarts, when you reach the applicationTimeout, if you force a restart via code or via the CFADMIN/server monitor To confirm my understanding, are you saying that on a very busy site, it's possible that OnApplicationStart might never run again once the app has started? (server admin and restarts aside.) Since the app is running fine for months and then all of a sudden switches configs, something else then must trigger a call to OnApplicationStart but with a screwy environment. (I'm going to add logging to track this down but I can't predict when the problem might happen again.) When you say you use cgi.server_name to determine which variables to use, are you being VERY explicity, as in the SERVER_NAME must match EXACTLY, or are you doing an if/else to say if its this then set as live else set as dev? My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production I can tell from a diagnostic page I have that configName's value ended up being dev. Fixing the problem is as easy as forcing a call to OnApplicationStart by hitting a special URL. Which makes me wonder under what circumstances OnApplicationStart can be called without CGI being set properly. Strange. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343359 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
I think I can see one possible cause of your problem Dave. You may actually have 2 applications running. one on yourdomain.com and another on www.yourdomain.com So if someone goes to yourdoamin.com and then www.yourdomain.com they will NOT be seeing the same application. So perhaps most people go to www.yourdomain.com, but every so often someone visits yourdoamin.cominstead, which would restart the application if it was outside the timeout period. To avoid this you need to add a redirect, so that only 1 domain is in use. either redirect www.yourdoamin.com to yourdomain.com or vice versa. And also change your code to explicit to avoid this problem if CGI.SERVER_NAME IS blah.com else ... staging else ... dev else redirect to blah.com On Mon, Mar 28, 2011 at 7:46 PM, Dave Watts dwa...@figleaf.com wrote: To confirm my understanding, are you saying that on a very busy site, it's possible that OnApplicationStart might never run again once the app has started? (server admin and restarts aside.) That's exactly correct. Since the app is running fine for months and then all of a sudden switches configs, something else then must trigger a call to OnApplicationStart but with a screwy environment. (I'm going to add logging to track this down but I can't predict when the problem might happen again.) It's entirely possible that (a) the server is stopping and restarting, which will cause all applications to stop, or (b) there's an explicit call to onApplicationStart somewhere within your code - this is actually pretty common. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343360 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
One thing to keep in mind, if you do not have a *unique *ApplicationName on your server, then the variables could be shared w/another application--which is especially dangerous on shared hosting. I've seen people roll out an application w/a common ApplicationName like MainApp and have issues w/their App scope being shared w/another application that also used a name of MainApp. Same thing happens if the Application.cfc/cfm doesn't define a ApplicationName. IMO, the safest thing you can do is name define ever ApplicationName with a hash of the current directory path: cfset this.name = hash(getDirectoryFromPath(getCurrentTemplatePath())) / That way you can use the same code w/every Application.cfc, but your virtually guaranteed to have a unique ApplicationName. -Dan On Mon, Mar 28, 2011 at 2:55 PM, Russ Michaels r...@michaels.me.uk wrote: I think I can see one possible cause of your problem Dave. You may actually have 2 applications running. one on yourdomain.com and another on www.yourdomain.com So if someone goes to yourdoamin.com and then www.yourdomain.com they will NOT be seeing the same application. So perhaps most people go to www.yourdomain.com, but every so often someone visits yourdoamin.cominstead, which would restart the application if it was outside the timeout period. To avoid this you need to add a redirect, so that only 1 domain is in use. either redirect www.yourdoamin.com to yourdomain.com or vice versa. And also change your code to explicit to avoid this problem if CGI.SERVER_NAME IS blah.com else ... staging else ... dev else redirect to blah.com On Mon, Mar 28, 2011 at 7:46 PM, Dave Watts dwa...@figleaf.com wrote: To confirm my understanding, are you saying that on a very busy site, it's possible that OnApplicationStart might never run again once the app has started? (server admin and restarts aside.) That's exactly correct. Since the app is running fine for months and then all of a sudden switches configs, something else then must trigger a call to OnApplicationStart but with a screwy environment. (I'm going to add logging to track this down but I can't predict when the problem might happen again.) It's entirely possible that (a) the server is stopping and restarting, which will cause all applications to stop, or (b) there's an explicit call to onApplicationStart somewhere within your code - this is actually pretty common. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343361 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
It's entirely possible that (a) the server is stopping and restarting, which will cause all applications to stop, or (b) there's an explicit call to onApplicationStart somewhere within your code - this is actually pretty common. Dave - For the sake of argument, if the server is restarted but no one hits a single page on the app, OnApplicationStart won't run right? So if it takes a page hit to call it, CGI should be defined, no? I just grepped my entire code base. The only call to onApplicationStart is my code in OnRequestStart which looks for a magic URL param. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343362 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
Dave - For the sake of argument, if the server is restarted but no one hits a single page on the app, OnApplicationStart won't run right? So if it takes a page hit to call it, CGI should be defined, no? Yes, unless that page request comes through an event gateway I guess. I just grepped my entire code base. The only call to onApplicationStart is my code in OnRequestStart which looks for a magic URL param. Are you sure that hasn't been invoked? You might want to (a) add logging, or (b) grep your web server log files. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343363 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
I think I can see one possible cause of your problem Dave. You may actually have 2 applications running. one on yourdomain.com and another on www.yourdomain.com So if someone goes to yourdoamin.com and then www.yourdomain.com they will NOT be seeing the same application. So perhaps most people go to www.yourdomain.com, but every so often someone visits yourdoamin.com instead, which would restart the application if it was outside the timeout period. To avoid this you need to add a redirect, so that only 1 domain is in use. either redirect www.yourdoamin.com to yourdomain.com or vice versa. And also change your code to explicit to avoid this problem if CGI.SERVER_NAME IS blah.com else ... staging else ... dev else redirect to blah.com Russ - I'm not sure I follow 100%. Whether the subdomain is there or not, IIS is configured to point to the same docroot so the same code will execute. I thought that the code manipulated the same application object if this.name was the same (which it is regardless of subdomain). Or am I missing something? ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343364 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
One thing to keep in mind, if you do not have a *unique *ApplicationName on your server, then the variables could be shared w/another application--which is especially dangerous on shared hosting. I've seen people roll out an application w/a common ApplicationName like MainApp and have issues w/their App scope being shared w/another application that also used a name of MainApp. Same thing happens if the Application.cfc/cfm doesn't define a ApplicationName. IMO, the safest thing you can do is name define ever ApplicationName with a hash of the current directory path: cfset this.name = hash(getDirectoryFromPath(getCurrentTemplatePath())) / That way you can use the same code w/every Application.cfc, but your virtually guaranteed to have a unique ApplicationName. -Dan Dan - That's a good tip but the app name is unique and I've verified that there are no unintended conflicts by dumping the application object's variables. (But, yes, I'm on shared hosting - meant to say that.) ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343365 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
On said diagnostic page, what is the value of CGI.SERVER_NAME and CGI. HTTP_HOST when the configName's value is dev? Bill - That's the key question. My diagnostic page only dumps the current config, not how it got there. I'm going to change that. Since I don't get an exception thrown within OnApplicationStart, I can assume that CGI is defined and CGI.SERVER_NAME is also defined. The only thing I can say is that, assuming my theory is right, the value of CGI.SERVER_NAME does not contain blah.com when I think it should. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343366 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
On 3/28/2011 11:10 AM, Dave Burns wrote: My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production Which means that if I (or any joker poking at your site to see if they can do something) who requests your site by its IP address could set your production server into dev mode. CGI.SERVER_NAME is probably populated, but it is populated by what I put into MY browser, just as long as that resulted in a request to YOUR server. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343367 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
On 3/28/2011 11:10 AM, Dave Burns wrote: My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production Which means that if I (or any joker poking at your site to see if they can do something) who requests your site by its IP address could set your production server into dev mode. CGI.SERVER_NAME is probably populated, but it is populated by what I put into MY browser, just as long as that resulted in a request to YOUR server. Well, since that code is in OnApplicationStart, only if you either a) knew the secret URL param and value to force a call to OnApplicationStart() or b) got lucky and were the very first page request to the app after a server restart. Both are possible but improbable. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343368 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: What event specifically triggers OnApplicationStart?
I suppose you haven't considered throwing some log recording in that area to help identify what might be going on? Regards, Andrew Scott http://www.andyscott.id.au/ -Original Message- From: Dave Burns [mailto:cft...@burnsorama.com] Sent: Tuesday, 29 March 2011 6:44 AM To: cf-talk Subject: Re: What event specifically triggers OnApplicationStart? Since I don't get an exception thrown within OnApplicationStart, I can assume that CGI is defined and CGI.SERVER_NAME is also defined. The only thing I can say is that, assuming my theory is right, the value of CGI.SERVER_NAME does not contain blah.com when I think it should. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343369 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
Dave, Since your config is based on the cgi.server_name variable, why don't you search your web server access logs for calls to your dev domain name? This would tell you when and what was accessed which might have reset your app. Dean On Mon, Mar 28, 2011 at 4:00 PM, Dave Burns cft...@burnsorama.com wrote: On 3/28/2011 11:10 AM, Dave Burns wrote: My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production -- --- Dean M. Lawrence INTERNET DATA TECHNOLOGY p // 888.438.4381 ext. 701 w // www.idatatech.com f // www.facebook.com/idatatech t // www.twitter.com/idatatech Social Marketing | SEO | Design | Internet Developm ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343370 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
Which means that if I (or any joker poking at your site to see if they can do something) who requests your site by its IP address could set your production server into dev mode. Not necessisarily, that would depend on how the web server was set to handle requests. One of my application has a similar setup and IIS will only pass the request to the application if the IP and hostname bindings are correct. If you made a request on the IP itself you'd just get a 301 response with a redirect to the main URL. Of course, if you knew the dev URL you could get into the application in development mode (also assuming you had proper credentials), but you couldn't put the live application into dev mode just by tweaking the HTTP request. -Justin ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343371 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: What event specifically triggers OnApplicationStart?
Is it possible that someone is accessing your site by it's ip address, in an attempt to fool it into something that could enable a hacking attempt? I've seen security scanning software do similar things. This is why I tend to have the production state be the default state, and have development and stage be explicitly defined. That way, if the system is not sure which configuration to use, it uses the most secure. Mark Sent from my mobile device. On 29/03/2011 7:58 AM, Dean Lawrence dean...@gmail.com wrote: Dave, Since your config is based on the cgi.server_name variable, why don't you search your web server access logs for calls to your dev domain name? This would tell you when and what was accessed which might have reset your app. Dean On Mon, Mar 28, 2011 at 4:00 PM, Dave Burns cft...@burnsorama.com wrote: On 3/28/2011 11:10 AM, Dave Burns wrote: My code looks like this: configName = dev if CGI.SERVER_NAME contains blah.com configName = production -- --- Dean M. Lawrence INTERNET DATA TECHNOLOGY p // 888.438.4381 ext. 701 w // www.idatatech.com f // www.facebook.com/idatatech t // www.twitter.com/idatatech Social Marketing | SEO | Design | Internet Developm ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343372 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm