ID: 46043 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Streams related Operating System: Linux, debian PHP Version: 5.2.6 New Comment:
But it does work fine (and returning the correct data) with a lower offset? The provided code also shows that the error only occurs at some cutoff point, meaning the stream supports seeking without any problems until the limit. I suppose this "it sometimes works" nature should be noted in the documentation or at least disallow file_get_contents() from using offset at all at a stream that does not support fseek(). Currently it is in a state where the feature could work one day and not the next (I suppose if the content is found within the first chunk of the request of a given limit) where it is not clear why the feature is not working. At least the text "stream does not support seeking" is confusing as some kind of offset usage is possible to a certain limit. Previous Comments: ------------------------------------------------------------------------ [2008-09-10 23:11:36] [EMAIL PROTECTED] You cannot seek on non-local files. ------------------------------------------------------------------------ [2008-09-10 14:55:42] [EMAIL PROTECTED] Description: ------------ file_get_contents() supports an offset. However, at certain times this gives an "stream does not support seeking" at a certain offset. This offset might differ with installations and the website a resource is requested from. Reproduce code: --------------- file_get_contents("http://stock.ter.dk/taske.jpg", null, null, 8000, 1000); Expected result: ---------------- The content should be returned Actual result: -------------- Warning: file_get_contents(): stream does not support seeking in Command line code on line 1 Warning: file_get_contents(): Failed to seek to position 8000 in the stream in Command line code on line 1 The exact cutoff-point seem to differ. A script such as the following gives different results at different servers. <?php $offset = 0; $length = 500; while ($file = file_get_contents("http://stock.ter.dk/taske.jpg", null, null, $offset, $length)) { print "$offset, $length\n"; $offset += $length; } ?> PHP 5.2.6-0.dotdeb.1 with Suhosin-Patch 0.9.6.2 (cli): 0, 500 500, 500 1000, 500 1500, 500 2000, 500 2500, 500 3000, 500 3500, 500 4000, 500 4500, 500 5000, 500 5500, 500 6000, 500 6500, 500 7000, 500 7500, 500 Warning: file_get_contents(): stream does not support seeking in /home/penguin/- on line 4 Warning: file_get_contents(): Failed to seek to position 8000 in the stream in /home/penguin/- on line 4 PHP 5.2.0 (cli) (built: Nov 26 2006 10:25:07): 0, 500 500, 500 1000, 500 Warning: file_get_contents(): stream does not support seeking in /home/penguin/- on line 4 Warning: file_get_contents(): Failed to seek to position 1500 in the stream. in /home/penguin/- on line 4 The behaviour is the same whether php-cli or mod_php is used, as seen at http://stock.ter.dk/filegetbug.php (as a side note, file_get_contents() [or rather, the http stream] could try to use a ranged request when an offset and range is present, with a fallback to the current behaviour if the webserver returns the whole file) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46043&edit=1