Bug #67351 [NEW]: copy() should handle HTTP 304 response
| From: | Andy_Schmidt at HM-Software dot com | Date: | Wed, 28 May 2014 02:23:58 +0000 |
| Subject: | Bug #67351 [NEW]: copy() should handle HTTP 304 response | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185942@lists.php.net to get a copy of this message | ||
From: Andy_Schmidt at HM-Software dot com
Operating system: Windows 2012
PHP version: 5.4.28
Package: Streams related
Bug Type: Bug
Bug description:copy() should handle HTTP 304 response
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=67351&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67351&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67351&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67351&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67351&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67351&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67351&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67351&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67351&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67351&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67351&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67351&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67351&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67351&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67351&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67351&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67351&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67351&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67351&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67351&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67351&r=mysqlcfg