As the name suggests, is there a quick way to download a file, but bring the timestamp along?
I'm writing a basic cache that, among other checks, determines (via get_headers
) if a given local file is the same as it's remote counterpart.
I know I can file_get_contents
/ file_put_contents
and then touch()
the file with the results of get_headers
, but the calling that is making another HTTP call (even if it is a HEAD call) and I'd only like to test Last-Modified as a last resort.
So is there a quick, "one HTTP call" way to download a file and preserve the timestamp? Some remote files live on an FTP server, but many are text files, and / or live on a web server.
EDIT: Someone suggested a related question, but my question differs, in that I'm looking to get the remote modified date without having to make a second call, which the copy()
based answer suggests
$http_response_header
seems to do the trick, as suggested below.