PHP - Download file and preserve timestamp?
<p>As the name suggests, is there a quick way to download a file, but bring the timestamp along?</p>

<p>I'm writing a basic cache that, among other checks, determines (via <code>get_headers</code>) if a given local file is the same as it's remote counterpart.</p>

<p>I know I can <code>file_get_contents</code> / <code>file_put_contents</code> and then <code>touch()</code> the file with the results of <code>get_headers</code>, 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.</p>

<p>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.</p>

<p>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 <code>copy()</code> based answer suggests</p>

<p><code>$http_response_header</code> seems to do the trick, as suggested below.</p>