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