ID: 44607 User updated by: amoo_miki at yahoo dot com -Summary: stream_get_line not working as expected Reported By: amoo_miki at yahoo dot com Status: Open Bug Type: Streams related -Operating System: Win32 +Operating System: All -PHP Version: 5.2CVS-2008-04-02 +PHP Version: 5.2.6 New Comment:
Tested this with PHP v5.2.6 on Windows 2008 Server and FreeBSD 7.0 and it still returns incorrect results. Previous Comments: ------------------------------------------------------------------------ [2008-04-02 12:14:33] amoo_miki at yahoo dot com Using: PHP 5.2.6RC4-dev (cli) (built: Apr 2 2008 08:04:44) Still i get the faulty output: Found in source at 9295 Location in stream: 15000 Rewinding... Location in stream: 15000 Attempting fix... Location in stream: 9307 Rewinding... Location in stream: 9307 ------------------------------------------------------------------------ [2008-04-02 11:56:25] amoo_miki at yahoo dot com Description: ------------ On some occasions stream_get_line acts weired by attempting the first seek without considering the "end of line" string. Below is the sample code that shows the problem with a workaround to temporarily solve the issue (that might ring some bells for the person who plans on fixing this). The code uses a small binary JPX file that can be fetched from http://barahmand.com/streambug/sample.txt Reproduce code: --------------- <?php $filename = 'sample.txt'; $arr = explode('<EndOfFrame>', file_get_contents($filename)); echo "Found in source at ".strlen($arr[0])."\n\n"; $fp = fopen($filename, "rb"); stream_get_line($fp, 15000, "<EndOfFrame>"); echo "Location in stream: ".ftell($fp)."\n"; echo "Rewinding...\n"; rewind($fp); stream_get_line($fp, 15000, "<EndOfFrame>"); echo "Location in stream: ".ftell($fp)."\n"; rewind($fp); echo "\nAttempting fix...\n"; stream_get_line($fp, 1, "<EndOfFrame>"); stream_get_line($fp, 15000, "<EndOfFrame>"); echo "Location in stream: ".ftell($fp)."\n"; echo "Rewinding...\n"; rewind($fp); stream_get_line($fp, 15000, "<EndOfFrame>"); echo "Location in stream: ".ftell($fp)."\n"; fclose($fp); ?> Expected result: ---------------- Found in source at 9295 Location in stream: 9307 Rewinding... Location in stream: 9307 Attempting fix... Location in stream: 9307 Rewinding... Location in stream: 9307 Actual result: -------------- Found in source at 9295 Location in stream: 15000 Rewinding... Location in stream: 15000 Attempting fix... Location in stream: 9307 Rewinding... Location in stream: 9307 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44607&edit=1