|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77927 popen() merge two consequent lines from stream (for big streams 1Mb or above)
Submitted: 2019-04-20 11:46 UTC Modified: 2019-05-05 04:22 UTC
From: alexeykirpa at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 7.2.17 OS: Windows 7+
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-04-20 11:46 UTC] alexeykirpa at gmail dot com
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:

Test script:
$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";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-20 12:22 UTC] alexeykirpa at gmail dot com
also you may use next script to generated MyTest.csv for tests


$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|-||50192\r\n");


By the way, if only '\n' is used for EOL, open works fine.
 [2019-04-24 12:23 UTC]
-Status: Open +Status: Feedback -Package: Streams related +Package: Filesystem function related -Assigned To: +Assigned To: cmb
 [2019-04-24 12:23 UTC]
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] <>
 [2019-05-05 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 27 18:01:24 2020 UTC