From:             [EMAIL PROTECTED]
Operating system: Linux 2.4.18
PHP version:      4CVS-2003-01-14 (stable)
PHP Bug Type:     Filesystem function related
Bug description:  stream_read() always passed count of 8192

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 bug report at http://bugs.php.net/?id=21641&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=21641&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=21641&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=21641&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=21641&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=21641&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=21641&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=21641&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=21641&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=21641&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=21641&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21641&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=21641&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=21641&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=21641&r=gnused

Reply via email to