<?php
function csvRows(string $path, string $sep = ',', string $enc = '"'): Generator {
$fh = fopen($path, 'r');
if ($fh === false) throw new RuntimeException("Cannot open $path");
try {
while (($row = fgetcsv($fh, 0, $sep, $enc, '\\')) !== false) {
yield $row;
}
} finally {
fclose($fh);
}
}
foreach (csvRows('big-export.csv') as $i => $row) {
if ($i === 0) continue; // skip header
// process $row — uses ~constant memory regardless of file size
}
Create a free account and build your private vault. Share publicly whenever you want.