ID:               23874
 User updated by:  kier at vbulletin dot com
 Reported By:      kier at vbulletin dot com
 Status:           Bogus
 Bug Type:         *Directory/Filesystem functions
 Operating System: Redhat Linux 8.0
 PHP Version:      4.3.2
 New Comment:

Thanks, I will make the appropriate changes to my code to reflect
this.

However, is it possible that the online documentation is now out of
date or misleading? To quote:

"fread() reads up to length bytes from the file pointer referenced by
handle. Reading stops when length bytes have been read or EOF (end of
file) reached, whichever comes first."

This is then followed by a code example that doesn't use fread() in a
while() loop. Perhaps the manual should be updated to note potential
problems when using fread() on remote resources?


Previous Comments:
------------------------------------------------------------------------

[2003-05-29 13:23:05] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You should be doing:

$contents = '';
while (($data = fread($fp, 99999999))) {
$contents .= $data;
}

A single fread() could get interupted by a signal and thus not fetch
all the data. By having the read code in a loop you protect yourself
against such a problem.

Better yet, use file_get_contents() to fetch the entire file in one go.
This function was introduced in PHP 4.3.0.

------------------------------------------------------------------------

[2003-05-29 12:16:48] kier at vbulletin dot com

After switching from PHP 4.3.2 RC2 to PHP 4.3.2 RC4 I noticed that a
lot of my scripts failed to properly open the files they were asked
to...

Here is an example script that works fine under PHP 4.3.2 RC2 but
breaks under 4.3.2 RC4 and later. I have not tried 4.3.2 RC3 so I can't
say whether the problem was introduced at the RC3 or RC4 stage.
Nonetheless, the problem still exists in PHP 4.3.2 Final.

<?php

$path = 'http://www.domain.com/some/large/page.html';

$fp = fopen($path, 'r');
$contents = fread($fp, 99999999);

echo '<pre>' . htmlspecialchars($contents) . '</pre>';

?>

This will output the HTML source of the page referenced in $path, but
under recent versions of PHP 4.3.2 the contents is truncated, having
not reached the end of the file.

It is worth noting that using

$contents = '';
while (!feof($fp))
{
    $contents .= fgets($fp, 100);
}

does not exhibit the fread() truncation problem, and neither does using
fread() on LOCAL files. The problem seems isolated to opening remote
files over HTTP with fread();

I have verified this bug on several servers under different PHP
configurations.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=23874&edit=1

Reply via email to