I've just had a strange issue with a client's website, my live domain was using my development domains Application settings. I've not had this issue before, and removing cflock
around the Application.dsn
(amongst other settings) resolved the issue.
As mentioned I have a live site *www.*
and development site *dev.*
, my development site is in a subfolder of the live site /dev/
and has it's own Application.cfc
.
My first question is, if I have variables in my Application scope in the dev folder will this overwrite the Application scope variables in the folder above? Will it consider it the same scope? If so, then this might explain what the issue and if not then I am stumped.
My second question is, how should I correct cflock
application scope variables in my application.cfc? Should I be doing this at all?
Here is my Application.cfc, advice would be greatly appreciated:
<cfcomponent output="true">
<cfimport taglib="taglib" prefix="func">
<!---
Check staging directory exists
--->
<cfset THIS.env = "staging">
<!---
Set application vars
--->
<cfset THIS.applicationTimeout = createTimeSpan(0,0,0,0)>
<cfset THIS.sessionManagement="Yes">
<cfset THIS.clientManagement = true>
<cfset THIS.clientStorage = "cookie">
<cfset THIS.loginStorage = "cookie">
<cfset THIS.setDomainCookies = false>
<cfset THIS.setClientCookies = true>
<cfset THIS.scriptProtect = true>
<cfset THIS.secureJSON = true> <!--- Added 12.06.13 --->
<!---
Check environment
Set application name
--->
<cfif THIS.env EQ "staging">
<cfset THIS.applicationName = "devenv">
<cfset THIS.dsn = "devenv">
<cfelse>
<cfset THIS.applicationName = "liveenv">
<cfset THIS.dsn = "liveenv">
</cfif>
<cfif #cgi.HTTP_HOST# NEQ "localhost">
<cfset THIS.dirpath = "http://#cgi.http_host#">
<cfset THIS.componentPath = "cfcs.">
<cfelse>
<cfset urlString = #mid(cgi.PATH_INFO, 2, 200)#>
<cfset THIS.localhostFolderName = #spanexcluding(urlString, "/")#>
<cfset THIS.dirpath = "http://localhost/#THIS.localhostFolderName#">
<cfset THIS.componentPath = "#THIS.localhostFolderName#.cfcs.">
</cfif>
<cfset THIS.name = THIS.applicationName>
<cfset THIS.sessiontimeout = createtimespan(0,0,20,0)>
<cfset THIS.setClientCookies = true>
<cfset THIS.visitor = true>
<cffunction name="onApplicationStart" returntype="void">
<cfset APPLICATION.name = THIS.applicationName>
<cfset APPLICATION.dsn = THIS.dsn>
<cfset APPLICATION.DSN = THIS.dsn>
<cfset APPLICATION.dirpath = THIS.dirpath>
<cfset APPLICATION.componentPath = THIS.componentPath>
<cfif #cgi.HTTP_HOST# EQ "localhost">
<cfset APPLICATION.localhostFolderName = THIS.localhostFolderName>
</cfif>
<!--- USED FOR PATHS AND URLS --->
<!--- Property image upload paths ---->
<cfset APPLICATION.paths = StructNew()>
<!---
Check environment
Set local root
--->
<cfif THIS.env EQ "staging">
<cfset APPLICATION.paths.localRoot = "c:\websites\foobar.co.uk\dev\">
<cfelse>
<cfset APPLICATION.paths.localRoot = "c:\websites\foobar.co.uk\">
</cfif>
<cfset APPLICATION.paths.logs = APPLICATION.paths.localRoot & "logs\">
<cfset APPLICATION.paths.logFile = APPLICATION.paths.logs & "site_log.txt">
<cfset APPLICATION.paths.property = StructNew()>
<cfset APPLICATION.paths.property.image = APPLICATION.paths.localRoot & "images\property\">
<cfset APPLICATION.paths.property.large = APPLICATION.paths.property.image & "large\">
<cfset APPLICATION.paths.property.thumb = APPLICATION.paths.property.image & "thumbs\">
<cfset APPLICATION.paths.property.cmsThumb = APPLICATION.paths.property.image & "thumbs\cms\">
<cfset APPLICATION.paths.property.pdf = APPLICATION.paths.localRoot & "pdf\">
<cfset APPLICATION.paths.property.pdfGenerated = APPLICATION.paths.property.pdf & "generated\">
<cfset APPLICATION.newsUploadPath = APPLICATION.paths.localRoot & "images\news\">
<cfset APPLICATION.articlesUploadPath = APPLICATION.paths.localRoot & "images\articles\">
<cfset APPLICATION.articlesThumbsDir = "../images/articles/thumbs/">
<cfset APPLICATION.articlesContentDir = "../images/articles/assets/">
<cfset APPLICATION.articlesAssetsDir = "../articles/assets/">
<!--- Site URLS ---->
<cfset APPLICATION.urls = StructNew()>
<cfset APPLICATION.urls.root = "http://" & CGI.server_name & "/">
<cfset APPLICATION.urls.com = "com">
<cfset APPLICATION.urls.tagLib = APPLICATION.urls.root & "taglib/">
<cfset APPLICATION.urls.cms.tagLib = "http://" & CGI.server_name & ":" & CGI.server_port & "/admin/tagLib/">
<cfset APPLICATION.RowsPerPage = 10>
<!--- Property URLS --->
<cfset APPLICATION.urls.property.pdf = APPLICATION.urls.root & "pdf/">
<cfset APPLICATION.urls.property.image = APPLICATION.urls.root & "images/property/">
<cfset APPLICATION.urls.property.large = APPLICATION.urls.root & "images/property/large/">
<cfset APPLICATION.urls.property.thumb = APPLICATION.urls.root & "images/property/thumbs/">
<cfset APPLICATION.urls.property.cmsThumb = APPLICATION.urls.root & "images/property/thumbs/cms/">
<cfset APPLICATION.urls.news.image = APPLICATION.urls.root & "images/news/">
<cfset APPLICATION.urls.articles.image = APPLICATION.urls.root & "images/articles/">
<cflock scope="Application" timeout="5" type="Exclusive">
<cfscript>
/* Commonly used objects and queries */
// DAOs
APPLICATION.propertyDAO = CreateObject("component", "cfcs.dataobjects.propertyDAO").init(APPLICATION.dsn);
APPLICATION.propertyImageDAO = CreateObject("component", "cfcs.dataobjects.property_imageDAO").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyImageDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_imageDAO").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyLocationDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_locationDAO").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyTypeDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_typeDAO").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyTenureDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_tenureDAO").init(APPLICATION.dsn);
APPLICATION.propertyGroupDAO = CreateObject("component", "cfcs.dataobjects.property_groupDAO").init(APPLICATION.dsn);
// Gateways
APPLICATION.propertyGateway = CreateObject("component", "cfcs.dataobjects.propertyGateway").init(APPLICATION.dsn);
APPLICATION.propertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_imageGateway").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_to_property_imageGateway").init(APPLICATION.dsn);
APPLICATION.propertyLocationGateway = CreateObject("component", "cfcs.dataobjects.property_locationGateway").init(APPLICATION.dsn);
APPLICATION.propertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_imageGateway").init(APPLICATION.dsn);
APPLICATION.propertyTypeGateway = CreateObject("component", "cfcs.dataobjects.property_typeGateway").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyTypeGateway = CreateObject("component", "cfcs.dataobjects.property_typeGateway").init(APPLICATION.dsn);
APPLICATION.propertyTenureGateway = CreateObject("component", "cfcs.dataobjects.property_tenureGateway").init(APPLICATION.dsn);
APPLICATION.propertyToPropertyTenureGateway = CreateObject("component", "cfcs.dataobjects.property_to_property_tenureGateway").init(APPLICATION.dsn);
APPLICATION.partnerGateway = CreateObject("component", "cfcs.dataobjects.partnerGateway").init(APPLICATION.dsn);
// Business Objects
APPLICATION.propertyBO = CreateObject("component", "cfcs.businessobjects.propertyBO").init(APPLICATION.dsn);
// Common queries
APPLICATION.qPartners = APPLICATION.partnerGateway.getAllRecords();
APPLICATION.qPropertyTypes = APPLICATION.propertyTypeGateway.getAllRecords();
APPLICATION.qPropertyTenures = APPLICATION.propertyTenureGateway.getAllRecords();
APPLICATION.qPropertyMinMaxSize = APPLICATION.propertyGateway.getMinMaxSize();
APPLICATION.qPropertyLocations = APPLICATION.propertyLocationGateway.getAllRecords();
</cfscript>
</cflock>
</cffunction>
<cffunction name="onSessionStart" returntype="void">
<cflock scope="Session" timeout="5" type="Exclusive">
<cfscript>
SESSION.propertySearchCriteria = CreateObject("component", "cfcs.beans.property_search_criteria").init();
SESSION.propertySearch = CreateObject("component", "cfcs.beans.property_search").init(SESSION.propertySearchCriteria);
</cfscript>
</cflock>
</cffunction>
Why do you change your application name based on the environment it's in? That makes no sense. The application is still the same app, irrespective of whether it's in prod, or you're staging it, or developing it.
Equally, same with the source code. You've got your dev site within your live website? How does this make any sense?
I dunno what's going on with your application variables, but they're bound to the application name (this.name
), not where the Application.cfc
is in the directory structure.
I suspect your zero applicationTimeout
is not helping matters much here. This basically means your application never actually persists... it'll be timing out every request. This makes no sense either.
You do not need to <cflock>
that code in onApplicationStart()
. ColdFusion will only allow one request to run onApplicationStart()
: all other requests will be queued until it's completed, by which time the application has started, so the queued requests won't even attempt to run it.
I think your problem is most likely causes by your poor application framework design, and this weird thing you're doing having dev and prod in the same source code tree (which defies all logic).
Sort your source code out, and the problem won't arise.