|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-04 07:44 UTC] mugeso at mugeso dot com
Description: ------------ When use in combination of stream_get_line and fseek, reading a file which has only 2 lines without ending on EOF(like below) does fail. This happens on only Windows and with only "2lines file without ending on EOF". Reproduce code: --------------- 2lines.txt -- a<CRLF> b<EOF> phpfile: -- <?php $file = dirname(__FILE__) . '/2lines.txt'; $fp = fopen($file, "rb"); var_dump(stream_get_line($fp, null, "\xd\xa")); fseek($fp, ftell($fp)); // expected that this does not affect result. var_dump(stream_get_line($fp, null, "\xd\xa")); Expected result: ---------------- string(1) "a" string(1) "b" Actual result: -------------- string(1) "a" bool(false) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 04:00:02 2025 UTC |
I can confirm this bug (on Ubuntu using PHP 5.2.10-2ubuntu6.5 with Suhosin-Patch 0.9.7 (cli) (built: May 21 2010 06:30:21) ) Here is a workaround function I made that seems to work: function stream_get_line_fixed($handle, $length, $ending) { // Only allow 3 tries since if there's a genuine failure we don't want to loop forever $tries = 3; $ret = FALSE; while ($ret === FALSE && $tries--) { $ret = stream_get_line($handle, $length, $ending); } return $ret; }