2014-09-04 138 views
1

请考虑以下代码:超过cfhttp超时错误

我发送一个SOAP请求,传递一个数字并获取7-8个字段的信息。我在肥皂信封中传递的 的数字正从170,000条记录的CSV文件中获取。下面是我在做什么的代码片段 :

<cffile action="READ" file="http://filepath/Myfile.csv" variable="FileContent"> 
<cfset CSVArray = CSVtoArray(FileContent)> 

<cfset CSVArrayLength = ArrayLen(CSVarray)> 

Total Records:<cfdump var="#CSVArrayLength#" > 

<cfloop index="LoopCount" from = "2" to = "#CSVArrayLength#"> 

<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope 
     xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:vtsInfoLookup" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:vtsInfoLookup"> 
    <SOAP-ENV:Header> 
     <userName>xyz</userName> 
     <password>JiunskeT1</password> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
      <infoLookup SOAP-ENV:EncodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > 

        <Number><cfoutput>#CSVArray[LoopCount][2]#</cfoutput></Number> 
       <userName>xyz</userName> 
       <password>passwd</password> 
      </infoLookup> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

</cfsavecontent> 

<cfhttp url ="https://myurl/abc.php?wsdl" method = "post" result = "httpResponse" throwonerror= "Yes"> 
    <cfhttpparam type="header" name="accept-encoding" value="no-compression" /> 
      <cfhttpparam type="header" name="content-type" value="application/soap+xml"> 

      <cfhttpparam type="header" name="content-length" value="#len(soap)#"> 
      <cfhttpparam type="xml" value="#trim(soap)#"> 

</cfhttp> 

<cfset XMLResponse = XmlParse(httpResponse.fileContent.Trim()) /> 
    <cfset arrNumber = XmlSearch(XMLResponse,"//*[name()='Number']") /> 
    <cfset Number = trim(arrNumber[1].xmlText)> 


    // Similarly parsing for other 7-8 fields 


    <cfquery name="vQuery" datasource="XX.XX.X.XXX"> 

    INSERT INTO 



      VALUES (<cfqueryparam cfsqltype = "cf_sql_varchar" value = "#trim(Number)#" null = "#NOT len(trim(Number))#"/>, 

        // 7 - 8 fields more here 
        ) 



    </cfquery> 


</cfloop> 

我是从2开始在这里的原因是,我的CSV文件的第一行的列名。该编号从CSV的第二行开始。这就是我在上面

我已经使用了CSVToarray功能提到了here

因为在我的服务器提到#CSVArray[LoopCount][2]#的原因 - 设置为>设置,为(秒)后超时请求值

请求已超出允许的时限标签:7200秒,我的请求后2个小时出现错误消息超时CFHTTP

所以,出17万个记录CSV,它插入1900后停止由于请求超时,SQL Server 2008中的记录数为0。

有没有办法让我的代码高效?阅读somewhere的人建议使用<cfthread>

+0

你总是可以增加超时只是该页面。或者您可以使用该csv创建一个.sql文件,然后您可以直接使用sql server执行,而不是将170k个不同的查询传递给sql。或者将插入块分成几块,每块有1000块插入块。 – 2014-09-04 17:28:45

回答

2

同时增加http超时+页面时间。 如果您正在处理如此大量的记录,请务必将记录分成小块。

插入17k条记录并在循环中调用插入查询是不可行的。

您可以简单地通过划分(例如:17000/2000 = 9文本/ SQL文件)来提高性能,并使用SQL功能将数据从SQL或文本文件导入数据库。

queryObj = new query(); 
queryObj.setDatasource(session.datasource); 
result = queryObj.execute(sql="LOAD DATA INFILE '#VARIABLES.textPath#' INTO TABLE tblEmployee FIELDS TERMINATED BY ':,:' LINES TERMINATED BY '\r\n' (emp_Name,emp_City)"); 

在文本文件中,新行被添加在新行“\ r \ n” 和字段delimeted用“:,:”

+0

这将是将重处理传递给数据库的好方法。但我想你不需要将它转换成多个文件,如果你将它发送到数据库。为了安全起见,只需在单独的线程中运行进程。 – 2014-09-05 07:22:00