Bug #77927 [Opn]: popen() merge two consequent lines from stream (for big streams 1Mb or above)

From: Date: Sat, 20 Apr 2019 12:22:01 +0000
Subject: Bug #77927 [Opn]: popen() merge two consequent lines from stream (for big streams 1Mb or above)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220533@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77927&edit=1 ID: 77927 User updated by: alexeykirpa at gmail dot com Reported by: alexeykirpa at gmail dot com Summary: popen() merge two consequent lines from stream (for big streams 1Mb or above) Status: Open Type: Bug Package: Streams related Operating System: Windows 7+ PHP Version: 7.2.17 Block user comment: N Private report: N New Comment: also you may use next script to generated MyTest.csv for tests <?php $fn = fopen("./MyTest.csv", "w+"); if($fn === false) die("failed to create file MyTest.csv"); for ($i = 0; $i < 21374; ++$i) fwrite($fn, "$i,2018-03-23 09:44:29,4624,S-1-0-0|-|-|0x0|S-1-5-7|ANONYMOUS LOGON|NT AUTHORITY|0x1ca14760|3|NtLmSsp |NTLM|TESTCMP|{00000000-0000-0000-0000-000000000000}|-|NTLM V1|128|0x0|-|0.0.0.16|50192\r\n"); fclose($fn); By the way, if only '\n' is used for EOL, open works fine. Previous Comments: ------------------------------------------------------------------------ [2019-04-20 11:46:31] alexeykirpa at gmail dot com Description: ------------ Initially I found problem when use popen() to process output of utility which produce CSV data (LogParser 2.2 if exactly). For 5MB stream usually 4..7 lines is bad. I redirect utility result to file and use fopen() - everything works correct. When I use "popen("type filename") - got same errors as with original utility output. Tested with php 7.2.12+ and with 7.3.x - same problem. NOTICE: with php 5.6.13 all works fine. Source file "MyTest.csv" which can be used to reproduce error you may download from url: http://www.sparc.tm/alex/mytest.rar Test script: --------------- <?php $fn = popen("type MyTest.csv", 'r'); // $fn = fopen("MyTest.csv", "r"); // this works! while (($data = fgetcsv($fn)) !== FALSE) { if (count($data) != 4) // CSV file always contain 4 columns { echo '[bad line] - ' . implode('; ', $data) . "\n"; continue; } } pclose($fn); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77927&edit=1

« previous php.bugs (#220533) next »