Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fileExists() vs CFHTTP checking remote files

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?

like image 519
Vlad Avatar asked Feb 07 '19 20:02

Vlad


1 Answers

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. 😜

like image 136
Alex Avatar answered Oct 27 '22 10:10

Alex