Bug #77927 [Opn->Fbk]: popen() merge two consequent lines from stream (for big streams 1Mb or above)
| From: | cmb@php.net | Date: | Wed, 24 Apr 2019 12:23:09 +0000 |
| Subject: | Bug #77927 [Opn->Fbk]: 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-220579@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
Updated by: cmb@php.net
Reported by: alexeykirpa at gmail dot com
Summary: popen() merge two consequent lines from stream (for
big streams 1Mb or above)
-Status: Open
+Status: Feedback
Type: Bug
-Package: Streams related
+Package: Filesystem function related
Operating System: Windows 7+
PHP Version: 7.2.17
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I can neither reproduce the reported behavior with PHP 7.2 nor
7.3. Please try again with one of the latest snapshots[1]. If the
issue persists, please state the exact filename of the snapshot,
and which Server API you are using, and what's the value of
auto_detect_line_endings (see PHP info).
[1] <https://windows.php.net/downloads/snaps/>
Previous Comments:
------------------------------------------------------------------------
[2019-04-20 12:22:01] alexeykirpa at gmail dot com
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.
------------------------------------------------------------------------
[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