php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35918 fread limited to 8K for local file w/ stream functions
Submitted: 2006-01-06 16:07 UTC Modified: 2006-01-06 16:48 UTC
From: cpuidle at gmx dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.1.1 OS: WinXP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cpuidle at gmx dot de
New email:
PHP Version: OS:

 

 [2006-01-06 16:07 UTC] cpuidle at gmx dot de
Description:
------------
After using stream_wrapper_register on php 5.1.1, fread is suddenly limited to 8K block size when reading local(!) files.

This behaviour is
a) not documentated
b) does not happen with PHP 5.0.5
c) not consistent (depending on use of stream_wrapper_register)

I had previously opened bug 35859, but did not receive an answer after the details had been discovered.

Thanks,
Andi

Reproduce code:
---------------
<?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);
?>

Expected result:
----------------
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520 (!!)

Actual result:
--------------
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 8192 (!!)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-06 16:48 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC