Does md5_file download the file it is getting the checksum from?
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? Basic开发者_JAVA技巧ally 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?
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.
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.
Yes, it actually downloads the file.
精彩评论