ID: 46043 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Bogus Bug Type: Streams related Operating System: Linux, debian PHP Version: 5.2.6 New Comment:
You cannot seek on non-local files. Previous Comments: ------------------------------------------------------------------------ [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