2013-06-13 4 views
0

방금 ​​클라이언트 웹 사이트에서 이상한 문제가 발생했습니다. 라이브 도메인에서 개발 도메인 응용 프로그램 설정을 사용하고있었습니다. 이전에이 문제가 발생하지 않았으며 Application.dsn (다른 설정 사이)에서 cflock을 제거하면 문제가 해결되었습니다.ColdFusion 8 - Application.cfc interference

제가 언급 한 바와 같이 라이브 사이트 www가 있습니다. 및 개발 사이트 dev., 내 개발 사이트는 라이브 사이트 /dev/의 하위 폴더에 있으며 자체 Application.cfc가 있습니다.

내 첫 번째 질문은 dev 폴더의 응용 프로그램 범위에 변수가 있으면 위의 폴더에있는 응용 프로그램 범위 변수를 덮어 씁니까? 동일한 범위로 간주할까요? 그렇다면이 문제에 대해 설명해 줄 수 있습니다.

두 번째 질문은 내 application.cfc에서 cflock 응용 프로그램 범위 변수를 어떻게 수정해야합니까? 내가 이렇게해야 할까?

은 여기 내 Application.cfc는 조언이 크게 감상 할 수있다 :

<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> 

+1

동일한 응용 프로그램 이름을 사용하고 있었습니까? 응용 프로그램 이름이 같으면 동일한 범위를 사용합니다. 다른 이름으로해서는 안됩니다. –

+0

live/dev env 변수 테스트를 설정할 때 일시적으로 동일한 응용 프로그램 이름을 공유했을 가능성이 있습니다. 그것은 분명히 그 문제를 설명 할 것입니다. Application.cfc에서 라이브/dev 테스트를 설정하는 최선의 방법은 무엇입니까? –

+0

응용 프로그램 이름이 다른 한 완전히 다른 응용 프로그램으로 처리됩니다. 그래서 네 논리가 괜찮은 것 같아. 지금까지 코드 블록을 잠그는 것만으로도 괜찮다고 생각합니다. 내 응용 프로그램에서 동일한 작업을 수행합니다. –

답변

0

응용 프로그램 이름이 현재 사용중인 환경에 따라 변경되는 이유는 무엇입니까? 그건 말이 안돼. 응용 프로그램은 찌르다, 또는 준비 중이거나 개발 중인지 여부와 관계없이 여전히 동일한 응용 프로그램입니다.

동일하게 소스 코드와 동일합니다. 라이브 웹 사이트에 dev 사이트가 있습니까? 이것이 어떻게 어떤 의미입니까?

응용 프로그램 변수에서 무슨 일이 일어나는지 모르겠지만 응용 프로그램 이름 (this.name)에 바인딩되어 있습니다 (Application.cfc이 디렉토리 구조에없는 경우).

0이 아닌 것으로 의심됩니다. applicationTimeout 여기에서 많은 도움이되지 않습니다. 이것은 기본적으로 애플리케이션이 실제로 지속되지 않는다는 것을 의미합니다 ... 모든 요청을 시간 초과 할 것입니다. 이것은 의미가 없습니다.

해당 코드가 onApplicationStart()<cflock> 일 필요는 없습니다. ColdFusion은 하나의 요청이 onApplicationStart() 만 실행하도록 허용합니다. 다른 모든 요청은 완료 될 때까지 대기하며 응용 프로그램이 시작될 때까지 대기열에있는 요청은 실행을 시도하지 않습니다.

난 당신의 문제가 가난한 응용 프로그램 프레임 워크 디자인에 의한 것 같아요. 그리고이 이상한 일은 개발자가 있고 모든 로직을 무시한 동일한 소스 코드 트리에서 찌르면되는 것 같습니다.

소스 코드를 정렬하면 문제가 발생하지 않습니다.

+0

* 감사합니다. ColdFusion은 onApplicationStart() *를 실행하는 요청 하나만 허용합니다 (여기서는 주요 문제는 아니지만 ..). 내 이해는 정상적인 경우 자동으로 호출 될 때만 해당됩니다. 응용 프로그램 시작 과정. 재설정을 수행하는 것과 같이 수동으로 호출하는 경우에는 자동으로 단일 스레드가 아닙니다. – Leigh

+0

실제로. 그리고 "이전에 내가 만든 것"은 다음과 같습니다 : http://cfmlblog.adamcameron.me/2012/07/onapplicationstart-is-not-intrinsically.html. 나는 그걸 던지면서 필요한 것 이상을 혼동하고 싶지 않았다. –

+0

답장을 보내 주셔서 감사합니다. @AdamCameron - 귀하의 질문에 대한 답변으로, 실제 환경과 개발 환경을 쉽게 교환 할 수 있도록 환경에 따라 응용 프로그램 이름을 변경했으며 두 개의 Application.cfc 파일을 보관할 필요가 없습니다. 이제는 나쁜 생각이므로 두 개의 App.cfcs가있는 것으로 돌아갑니다. dev는 같은 폴더 트리에 호스팅 제한 때문에 있습니다. –

0

당신은 당신의 응용 프로그램 이름을 설정하는 조건부 논리를 사용할 수 있습니다.

if (YouAreHappy and YouKnowIt) { 
This.name = "ClapYourHands"; 
} 
else { 
This.name = "StompYourFeet"; 
} 

실생활에서 if 조건은 실제 환경과 테스트 환경이 다른 것입니다. cgi.http_host가 좋은 후보입니다.

관련 문제