|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-29 08:28 UTC] ivan dot enderlin at hoa-project dot net
Description:
------------
When calling stream_get_contents() with $offset >= ftell() *through a stream wrapper*, the internal pointer of the stream is moved but stream_get_contents() throws an error: "Failed to seek to position $offset in the stream".
While monitoring the source code (ext/standard/streamsfuncs.c, at line 404, no kidding ;-)), it appears that it is a normal behaviour since seek_res is set to -1 at line 426 (with the code bellow). I did not understand why (I looked at php_stream_seek implementation but I was not able to understand).
Change fopen('foo://bar', 'rb') for fopen(__FILE__, 'rb') and the issue disappears. That's why I think it is related to stream wrapper, but I cannot ensure that.
Test script:
---------------
<?php
class StreamWrapper {
protected $_stream = null;
public function stream_open ( $path, $mode, $options, &$openedPath ) {
$this->_stream = fopen(__FILE__, $mode);
return true;
}
public function stream_seek ( $offset, $whence = SEEK_SET ) {
var_dump('seek to ' . $offset);
return fseek($this->_stream, $offset, $whence);
}
public function stream_read ( $count ) {
return fread($this->_stream, $count);
}
public function stream_stat ( ) {
return fstat($this->_stream);
}
public function stream_eof ( ) {
return feof($this->_stream);
}
}
stream_wrapper_register('foo', 'StreamWrapper');
$a = fopen('foo://bar', 'rb');
var_dump(stream_get_contents($a, 30, 4));
Expected result:
----------------
no error
Actual result:
--------------
error
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 15:00:01 2025 UTC |
Oh also the bug disappears with: fseek($a, 4); stream_get_contents($a, 30);