我有一个 Web 应用程序,它在 Windows/IIS 服务器上使用 ColdFusion 8 批量生成数百个 PDF。
该过程在我的开发和登台服务器上运行良好,但当然客户端很便宜并且只为共享主机付费,这不如我的开发/登台盒快。因此,PDF 生成线程超时。
流程是这样的:
- 运行页面以生成 PDF。
- 运行查询以确定需要生成哪些 PDF,然后循环为需要生成的每个 PDF 触发应用程序范围的 UDF 调用。
- 该 UDF 查找给定项目的信息,然后为 PDF 生成创建一个线程,以防止生成减慢页面速度。
- 该线程仅使用 CFDocument 创建 PDF 并将其保存到磁盘,然后终止。
线程不会重新加入,并且没有任何东西在等待它们中的任何一个完成。进行 UDF 调用的页面在几毫秒内完成;是线程本身超时。
这是 UDF(和线程创建)的代码:
<cffunction name="genTearSheet" output="false" returntype="void">
<cfargument name="partId" type="numeric" required="true"/>
<!--- saveLocation can be a relative or absolute path --->
<cfargument name="saveLocation" type="string" required="true"/>
<cfargument name="overwrite" type="boolean" required="false" default="true" />
<cfset var local = structNew() />
<!--- fix save location if we need to --->
<cfif left(arguments.saveLocation, 1) eq "/">
<cfset arguments.saveLocation = expandPath(arguments.saveLocation) />
</cfif>
<!--- get part info --->
<cfif structKeyExists(application, "partGateway")>
<cfset local.part = application.partGateway
.getByAttributesQuery(partId: arguments.partId)/>
<cfelse>
<cfset local.part = createObject("component","com.admin.partGateway")
.init(application.dsn).getByAttributesQuery(partId: arguments.partId)/>
</cfif>
<!--- define file name to be saved --->
<cfif right(arguments.saveLocation, 4) neq ".pdf">
<cfif right(arguments.saveLocation, 1) neq "/">
<cfset arguments.saveLocation = arguments.saveLocation & "/" />
</cfif>
<cfset arguments.saveLocation = arguments.saveLocation &
"ts_#application.udf.sanitizePartNum(local.part.PartNum)#.pdf"/>
</cfif>
<!--- generate the new PDF in a thread so that page processing can continue --->
<cfthread name="thread-genTearSheet-partid-#arguments.partId#" action="run"
filename="#arguments.saveLocation#" part="#local.part#"
overwrite="#arguments.overwrite#">
<cfsetting requestTimeOut=240 />
<cftry>
<cfoutput>
<cfdocument format="PDF" marginbottom="0.75"
filename="#attributes.fileName#" overwrite="#attributes.overwrite#">
<cfdocumentitem type="footer">
<center>
<font face="Tahoma" color="black" size="7pt">
pdf footer text here
</font>
</center>
</cfdocumentitem>
pdf body here
</cfdocument>
</cfoutput>
<cfcatch>
<cfset application.udf.errorEmail(application.errorEmail,
"Error in threaded PDF save", cfcatch)/>
</cfcatch>
</cftry>
</cfthread>
</cffunction>
如您所见,我尝试<cfsetting requestTimeout=240 />
在线程顶部添加一个以尝试使其寿命更长...没有骰子。当我看到CFThread 标签有一个超时参数时,我也有点兴奋,但后来意识到它只适用于加入线程(action=join)时。
在 ColdFusion Administrator 中更改默认超时不是一个选项,因为这是一个共享主机。
如果有人对如何使这些线程寿命更长有任何想法,我将不胜感激。