ID:               31085
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php at webdevelopers dot cz
 Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Linux 2.6.6 (gcc 3.3.4)
 PHP Version:      5.0.2
-Assigned To:      
+Assigned To:      wez
 New Comment:

Returning !feof() in stream_eof() seems to 'fix' this.

 looks like the LIVENESS test in main/streams/userspace.c:838 uses
reverse logic?


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

[2004-12-14 11:41:28] php at webdevelopers dot cz

Description:
------------
PHP caches the userarea wrappers - it results for example
to WRAPPER::stream_read(8192) call by PHP even if the user issued
fread($f, 10);
If the file is for example 20 bytes long then user gets EOF immediately
after
first fread($f, 10) because PHP cached it by calling
WRAPPER::stream_read(8192) instead!

Example:
(file size is 20 bytes)
user: $f=fopen(..., 'r');
zend: stream_open(...);
zend: stream_read(8192); // And we immediately get EOF in my example
(8192 > 20)
user: fread($f, 10); // Reads first 10 bytes
user: feof($f);
zend: stream_eof(...); // Result is TRUE thus when feof() used in
cyclus it does not iterate even if there are 10 bytes more in this
example.


Reproduce code:
---------------
stream_wrapper_register('xyz', 'MyStream') or die('Failed to register X
protocol.');
test('xyz://me.txt');
test('./test_me2.txt');
function test($fileName) {
  echo "TEST: $fileName\n";
  $f=fopen($fileName, 'w+'); fwrite($f, '123456789'); fclose($f);
  $f=fopen($fileName, 'r');
  while(!feof($f)) { echo "[".fread($f, 5)."]\n";}
  fclose($f);
}
class MyStream {
  private $f;
  function stream_open($path, $mode, $options, &$opened_path) {
    $path=str_replace('xyz://', './test_', $path);
    return (bool) $this->f=fopen($path, $mode);
  }
  function stream_read($count) {return fread($this->f, $count);}
  function stream_write($data) {return fwrite($this->f, $data);}
  function stream_tell() {return ftell($this->f);}
  function stream_eof() {return feof($this->f);}
  function stream_seek($offset, $whence) {return fseek($this->f,
$offset, $whence);}
  function stream_close() {return fclose($this->f);}
}


Expected result:
----------------
TEST: xyz://me.txt
[12345]
[6789]
TEST: ./test_me2.txt
[12345]
[6789]


Actual result:
--------------
TEST: xyz://me.txt
TEST: ./test_me2.txt
[12345]
[6789]



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


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

Reply via email to