|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-04-20 11:46 UTC] 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);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
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.