#35859 [Csd->Opn]: fread limited to 8K

From: Date: Mon, 16 Jan 2006 08:19:35 +0000
Subject: #35859 [Csd->Opn]: fread limited to 8K
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969371618@lists.php.net to get a copy of this message
ID: 35859 User updated by: cpuidle at gmx dot de Reported By: cpuidle at gmx dot de -Status: Closed +Status: Open Bug Type: Documentation problem Operating System: WinXP SP2 PHP Version: 5.1.1 New Comment: Sorry, but the documentation is still wrong- did anybody ever look at the code to reproduce?! "or (for userspace streams) when 8192 bytes have been read whichever comes first." When stream wrappers are not used (even unrelated protocols count as stream wrapper use), the 8K limit is not in effect. So- documentation wrong again... Previous Comments: ------------------------------------------------------------------------ [2006-01-13 12:00:42] vrana@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Reading stops when up to length bytes have been read, EOF (end of file) is reached, (for network streams) when a packet becomes available, or (for userspace streams) when 8192 bytes have been read whichever comes first." ------------------------------------------------------------------------ [2006-01-09 22:14:52] cpuidle at gmx dot de Not sure why you couldn't find the code or what else you need but here it is again: 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 (>8k) $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 (!!) Could you point me to where it's documented? ------------------------------------------------------------------------ [2006-01-09 19:35:02] vrana@php.net This bug really miss the reproduce script ("Unfortunately the sample code does not reproduce the problem standalone, but demonstrates the effect."). The point lies in using fread() together with stream wrappers (it's somehow documented now) and the 8K limit. ------------------------------------------------------------------------ [2006-01-09 18:49:22] cpuidle at gmx dot de For code to reproduce see Bug #35918. Problem is that the block size is only in effect after stream wrapper functions are being used. And only in 5.1.1, not 4.x (obviously) or 5.0.5. This is what makes the thing fishy and imho more than a documentation issue. Thanks, Andi ------------------------------------------------------------------------ [2006-01-09 18:03:27] nlopess@php.net the packet size is 8k (8192).. ------------------------------------------------------------------------ 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

« previous php.doc (#969371618) next »