|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67351 copy() should handle HTTP 304 response
Submitted: 2014-05-28 02:23 UTC Modified: -
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Andy_Schmidt at HM-Software dot com Assigned:
Status: Open Package: Streams related
PHP Version: 5.4.28 OS: Windows 2012
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-05-28 02:23 UTC] Andy_Schmidt at HM-Software dot com
Using the "If-Modified-Since" header is desirable when copying from a remote web server, to avoid unnecessarily copying unmodified files across the Internet.

However, the copy() function does not handle a HTTP 304 response, which indicates that the file on the web server is NOT newer than the local file. It ignores the response code, uses the (empty) content from the HTTP response and overwrites the existing local file with a zero length file. This is not a useful course of action.

Since the copy() function DOES handle other 3xx return codes appropriately (such as following permanent and temporary redirects), it would make particular sense to also handle 304.

Test script:
// $fURI: 		URL to a file located on a web server
// $target_file:	Path to a local file	

$arrRequestHeaders = array(
		'method'		=>'GET',
		'protocol_version'	=>1.1,
		'follow_location'	=>1,
		'header'		=>'If-Modified-Since: '.date( 'r', filemtime( $target_file ) )."\r\n"
$rc = copy( $fURI, $target_file, stream_context_create($arrRequestHeaders) );

Expected result:
When a HTTP 304 response is returned, the copy() function must NOT touch the target file. copy() could return a FALSE (indicating that nothing was copied), and the script could check the HTTP response to decide on any specialized processing.

Actual result:
When a HTTP 304 response is returned, the copy() function returns TRUE and overrides the target file with a 0 length file.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 21:01:25 2020 UTC