Bug #19422 [Csd]: _read truncates cache files
| From: | fletcher dot moore at comm dot gatech dot edu | Date: | Mon, 21 May 2012 19:02:15 +0000 |
| Subject: | Bug #19422 [Csd]: _read truncates cache files | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-8678@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=19422&edit=1
ID: 19422
Updated by: fletcher.moore@comm.gatech.edu
Reported By: fletcher dot moore at comm dot gatech dot edu
Summary: _read truncates cache files
Status: Closed
Type: Bug
Package: Cache_Lite
Operating System: Irrelevant
Package Version: 1.7.14
PHP Version: 5.3.12
Assigned To: tacker
Roadmap Versions:
New Comment:
Works like a charm. Thanks!
Previous Comments:
------------------------------------------------------------------------
[2012-05-21 13:54:42] tacker
-Status: Assigned
+Status: Closed
-Package Version: 1.7.12
+Package Version: 1.7.14
Hoi Fletcher,
this has been fixed in the latest release.
Please check the latest release.
I've created a test for the bug:
https://github.com/pear/Cache_Lite/blob/master/tests/pearbug19422.phpt
Please feel free to submit a PR if the proplem persists:
https://github.com/pear/Cache_Lite
------------------------------------------------------------------------
[2012-05-19 11:24:42] tacker
-Status: Feedback
+Status: Assigned
-Operating System: OS X 10.7.3
+Operating System: Irrelevant
-Assigned To:
+Assigned To: tacker
According to the php docs for fread [1] the problem might be a buffered
stream:
> if the stream is read buffered and it does not represent a plain file,
at most one
read of up to a number of bytes equal to the chunk size (usually 8192)
is made;
Using stream_get_contents is not an option, as Cache_Lite must run under
PHP4.
Using fread() in a loop until there is no more data is the right
solution.
I'll have a look into that in the next days.
[1] http://php.net/manual/en/function.fread.php
------------------------------------------------------------------------
[2012-05-18 16:48:51] crackwilding
Sure thing. Here's the relevant part of the function:
function hg_reader_cacheHandler($id, $type='feed', $cacheTime=3600) {
$xml = array();
$cacheOpt = array();
$cacheOpt['cacheDir'] = variable_get('hg_cache_location',
file_default_scheme() .
'://hg/cache' . '/');
$cacheOpt['cache_time'] = $cacheTime;
$cl = new Cache_Lite($cacheOpt);
$cl->setToDebug();
if (($data = $cl->get($id . $type)) AND
(!array_key_exists('clearcache', $_GET)))
{
$xml['err'] = '';
$xml['data'] = $data;
} else {
// Pull XML for feed
if ($type == 'feed') {
$xml_url = HG_URL . '/xml/' . $id;
} else {
// Pull XML for node
$xml_url = HG_URL . '/node/' . $id . '/xml';
}
}
A couple notes: variable_get() and file_default_scheme() are Drupal API
functions.
The line those appear in set $cacheOpt['cacheDir'] to
"public://hg/cache/" which is
writeable and all that. The cache files appear there, they just don't
ever get used.
The code that registers the public stream wrapper is in Drupal's
file.inc:
http://api.drupal.org/api/drupal/includes%21stream_wrappers.inc/class/DrupalPubli
cStreamWrapper/7
I think it would also be possible to loop the fread() function within
_read so that it
pulls the whole file. Someone mentioned that in a Cache_lite bug report
long ago,
but the thread (http://pear.php.net/bugs/bug.php?id=9836) was closed
when the
guy failed to produce a patch. I could probably write one â I haven't
tried that
approach yet, but it does seem to me better for backward compatibility
purposes.
------------------------------------------------------------------------
[2012-05-18 08:30:47] tacker
-Status: Open
+Status: Feedback
Hoi crackwilding,
thank you for the report.
Please provide the relevant code sections of your app which reproduces
this error.
Thanks!
------------------------------------------------------------------------
[2012-05-17 23:08:24] crackwilding
Description:
------------
I'm trying to read and write cache files to a directory specified
by a stream wrapper generated by Drupal 7. The _read
function is truncating the files to 16,352 characters, which
renders them useless, not least of which because they fail
checksum comparisons.
This can be fixed by changing line 734 to:
$data = @stream_get_contents($fp);
This renders the $length variable sort of pointless, and of
course it causes some issues with backward compatibility, but
I wanted to know whether I'm missing something before
diving into it any deeper.
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19422&edit=1