fileExists() 与 CFHTTP 检查远程文件

fileExists() vs CFHTTP checking remote files

fileExists远程文件检查是否使用cfhttp头?

我担心检查远程文件时 fileExists 通过 CFHTTP 的速度

<cfset imgExist = FileExists('https://qph.fs.quoracdn.net/main-qimg-e8b07145ae25974d4902168818241326.webp') >
<cfdump var="#imgExist#">
-- Returns Yes --

FileExists函数是否使用CFHTTP头?

<cfhttp method="head" url="someimage" resolveurl="no" throwonerror="no" timeout="2" />

在检查远程文件是否存在时,FileExists 比 CFHTTP 有什么优势?

另外,在服务器负载方面,FileExists 是否比 CFHTTP 更好?

Is the FileExists function uses CFHTTP head?

是的,fileExists 利用 Commons Virtual File System,它转换为对 Web 资源的 HTTP HEAD 请求。

What is the advantage of FileExists over CFHTTP when checking if the remote file exists?

从理论上讲,实现可以很容易地适应网络资源的特定规则,而使用 cfhttp 将是一个具体的实现。但是,您可以只包装 cfhttp 以便自己轻松调整它,而不是依赖于最新版本的 Jakarta VFS。

Also is FileExists better than CFHTTP in terms of server load?

不,现在这两个调用都会产生一个 HTTP HEAD 请求。我无法衡量它们之间的实际性能差异。

如评论中所述,您可能不应该使用 fileExists,因为:

  1. Adobe 没有记录检查 Web 资源,它更像是一个不错的 side-effect 因为实现使用了下面的 VFS。
  2. 您对实施没有任何控制权。示例:如果您需要添加额外的 header(因为您正在检查的网络服务器要求您这样做),那么您将无法使用 fileExists.

所以我的建议是:编写一个简洁的函数,使用 cfhttp method="HEAD" 并在需要时调整函数。不要相信未记录的功能,尤其是涉及 CF 时。