ID:               35859
 User updated by:  cpuidle at gmx dot de
 Reported By:      cpuidle at gmx dot de
 Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: WinXP SP2
 PHP Version:      5.1.1
 New Comment:

Any chance to get an answer? Both behaviour and documentation could at
least be consistent...

Thanks,
Andi


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

[2006-01-01 14:09:55] cpuidle at gmx dot de

OK. I was further looking at the problem (yes, it *is* a problem, at
least in the documentation). I've now found that fread will normally
read the entire (local) file, not limited to 8K. However, as soon as
stream_wrapper_register is used, the 8K limit is effective:

<?php

class VariableStream {
    var $position, $varname;
    
    function stream_open($path, $mode, $options, &$opened_path) {
        $url = parse_url($path);
        $this->varname = $url['host'];
        $this->position = 0;
        return true;
    }
    
    function stream_read($count) {
        $ret = substr($GLOBALS[$this->varname], $this->position,
$count);
        $this->position += strlen($ret);
        return $ret;
    }
    
    function stream_eof() {
        return $this->position >= strlen($GLOBALS[$this->varname]);
    }
    
    function stream_stat() {
        return array('size' => strlen($GLOBALS[$this->varname]));
    }  
    
    function url_stat() {
        return array();
    }
}

function read($filename) {
    if (file_exists($filename) && ($fd = @fopen($filename, 'rb'))) {
        $size = filesize($filename);
        $contents = fread($fd, $size);
    }
    echo("\$filename $filename: \$size: $size strlen(\$contents):
".strlen($contents)."<br/>");
}

// local file
$filename = 'templates/elegant/show.tpl';

// will read entire file
read($filename);

stream_wrapper_register('var', 'VariableStream');

// will only read 8K
read($filename);

?>

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

[2005-12-31 15:40:41] cpuidle at gmx dot de

If Wez says this is the expected behaviour, then fine, but:

a) document it
b) don't change it around inbetween releases

Cheers,
Andi

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

[2005-12-31 15:36:16] cpuidle at gmx dot de

The documentation reads:

> fread() reads up to length bytes from the file pointer referenced by
handle. Reading stops when up to length bytes have been read, EOF (end
of file) is reached, or (for network streams) when a packet becomes
available, whichever comes first. 

Neither of the conditions is satisfied. The internal 8K limit is *not*
documented?

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

[2005-12-31 15:32:09] cpuidle at gmx dot de

Thanks. Could you verify that this behaviour has been changed between
5.0.5 and 5.1.1? Would it be worth to add to the documentation, that
for local files 8K is an internal limit?

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

[2005-12-31 15:27:51] [EMAIL PROTECTED]

See comments in bug #30936


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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/35859

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

Reply via email to