php.net |  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: -
Votes:2
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Andy_Schmidt at HM-Software dot com
New email:
PHP Version: OS:

 

 [2014-05-28 02:23 UTC] Andy_Schmidt at HM-Software dot com
Description:
------------
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:
---------------
<?php
// $fURI: 		URL to a file located on a web server
// $target_file:	Path to a local file	

$arrRequestHeaders = array(
	'http'=>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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 20 16:01:21 2019 UTC