超过cfhttp超时错误

时间:2014-09-04 17:12:03

标签: coldfusion coldfusion-9 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的第二行开始。这就是我之前提到的#CSVArray[LoopCount][2]#

的原因

我使用了here

中提到的CSVToarray功能

因为,在我的服务器 - &gt;设置中,超时请求(秒)后的值设置为7200秒,我的请求在2小时后超时,并显示错误消息:

请求已超过允许的时间限制标记:cfhttp

因此,在CSV中的170,000条记录中,由于请求超时,它在SQL Server 2008中插入了19000条记录后停止了。

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

1 个答案:

答案 0 :(得分: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'中添加新行 和字段用':,:'

分隔