5
votes

Is the fileExists remote file checking uses cfhttp head?

I'm concerned on the speed of fileExists over CFHTTP when checking remote files

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

Is the FileExists function uses CFHTTP head?

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

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

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

1
The fact that you're unsure what FileExists() uses behind the scenes (and so am I) is why I'd lean towards using cfhttp (-; CFHttp is well known, and it's specifically designed for working with url's, which is really what you're dealing with. Granted using FileExists with remote files probably is kosher (and likely does use HEAD) there's not much in the way of documentation. The main docs don't even mention url's, let alone capabilities and/or limitations. – SOS
Maybe throw together a quick test? As someone who hates using cfhttp (for various reasons), I would lean towards FileExists, though I have to admit that I’ve never used it for urls. – Redtopia
True, CFHttp does have it's issues, but at least most of them are well documented or others have encountered them before. AFAIK there isn't any documentation on what to expect with FileExists() or if it even supports things like authentication, cookies, etc.. That's why I'd lean towards using cfhttp, or failing that use java directly. – SOS

1 Answers

4
votes

Is the FileExists function uses CFHTTP head?

Yes, fileExists utilizes the Commons Virtual File System, which translates to a HTTP HEAD request for web resources.

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

Theoretically the implementation could easily adjust to specific rules for web resources, while using cfhttp would be a concrete implementation. However, you could just wrap cfhttp to easily adjust it yourself, rather than relying on the newest version of Jakarta VFS.

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

No, right now both calls result in a HTTP HEAD request. I could not measure a real performance difference between them.

As mentioned in the comments, you should probably NOT use fileExists, because:

  1. Checking web resources is not documented by Adobe, it's more like a nice side-effect because the implementation uses VFS beneath.
  2. You do not have any control over the implementation. Example: In case you ever need to add an additional header (because the webserver you are checking requires you to do so), you would be out of luck with fileExists.

So my recommendation is: Write a neat function that uses cfhttp method="HEAD" and adjust the function whenever you need to. Don't trust an undocumented feature, especially not when it comes to CF. 😜