ID:               21641
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Linux 2.4.18
 PHP Version:      4CVS-2003-01-14 (stable)
 New Comment:

This is not a bug; PHP uses an internal read buffer 8192 bytes in
length in order to be more efficient.
You should note that fread() returns the correct number of bytes to
your script.


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

[2003-01-14 14:59:09] [EMAIL PROTECTED]

The stream_read() method of a class registered with
stream_register_wrapper() is always passed 8192 as a count of bytes to
read no matter what the second argument is to an fread() on that
stream. This is reproduceable with the following class and test code:

<?php
class Stream_File {
    var $fn;
    var $fp;

    function stream_open($path, $mode, $options, &$opened_path)
    {
        $url = parse_url($path);
        $this->fp = fopen($this->fn = $url['path'],$mode);
        return ($this->fp ? true : false);
    }

    function stream_close()
    {
        fclose($this->fp);
    }

    function stream_read($count)
    {
        error_log("stream_read: $count ");
        return fread($this->fp,$count);
    }
    
    function stream_write($data)
    {
        return fwrite($this->fp,$data);
    }
    function stream_eof()
    {
        return feof($this->fp);
    }
    function stream_tell()
    {
        return ftell($this->fp);
    }
    function stream_seek($offset,$whence)
    {
        return fseek($this->fp,$offset,$whence);
    }
    function stream_flush()
    {
        return fflush($this->fp);
    }
}

stream_register_wrapper('filetest', 'Stream_File') or die("Can't
register filetest on Stream_File");

$fp = fopen("filetest://localhost/tmp/hello","w+");
fwrite($fp, "testing\n");
rewind($fp);
$data = fread($fp, 10);
echo "$data\n";
rewind($fp);
$data = fread($fp,32000);
echo "$data\n";
fclose($fp);
?>

Each time fread() is called on the stream, the error_log() call in
stream_read() prints:

stream_read: 8192

instead of "stream_read: 10" or "stream_read: 32000"


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


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

Reply via email to