Reputation: 556
If I use md5_file to get the checksum of a remote file in PHP, does it download the file and them get the checksum or does it request the checksum from the remote server? Basically what I'm trying to figure out is if it is less bandwidth to do a MD5 check on a file to see if it has changed before I re-download the file, but if md5_file downloads the file to a temp location then does the check, I might as well just download the file straight-up anyway, right?
Upvotes: 1
Views: 1247
Reputation: 145472
Expanding on Wodins answer: It's less bandwidth if you issue a HEAD
request on the remote file. The webserver response usually includes a hash in the form of an ETag
header. Use:
$h = get_headers($remote_file, true);
$hash = $h["ETag"] or $hash = $h["Last-Modified"];
See http://php.net/manual/en/function.get-headers.php for examples.
Upvotes: 3
Reputation: 3528
It would have to, yes. What you should probably do instead is an "if modified since" request that will only send you the file if the timestamp is newer than the time you specify. I don't know how you do that with php though.
Upvotes: 3