Task/File/Csv/CsvSplitterTask.php
protected function splitCsv(CsvFile $csv, $maxLines)
    {
        $tmpFilePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_'.uniqid('process', false).'.csv';
        $tmpFile = fopen($tmpFilePath, 'wb+');
        if (false === $tmpFile) {
            throw new \RuntimeException("Unable to open temporary file {$tmpFilePath}");
        }
        $splitCsv = new CsvResource(
            $tmpFile,
            $csv->getDelimiter(),
            $csv->getEnclosure(),
            $csv->getEscape(),
            $csv->getHeaders()
        );
        $splitCsv->writeHeaders();

        while ($splitCsv->getCurrentLine() < $maxLines && !$csv->isEndOfFile()) {
            $raw = $csv->readRaw();
            if (false === $raw) {
                continue; // This is probably an empty line, no harm to skip it
            }
            $splitCsv->writeRaw($raw);
        }
        $splitCsv->close();

        return $tmpFilePath;
    }
protected function splitCsv(CsvFile $csv, $maxLines)
    {
        $tmpFilePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_'.uniqid('process', false).'.csv';
        $tmpFile = fopen($tmpFilePath, 'wb+');
        if (false === $tmpFile) {
            throw new \RuntimeException("Unable to open temporary file {$tmpFilePath}");
        }
        $splitCsv = new CsvResource(
            $tmpFile,
            $csv->getDelimiter(),
            $csv->getEnclosure(),
            $csv->getEscape(),
            $csv->getHeaders()
        );
        $splitCsv->writeHeaders();

        while ($splitCsv->getCurrentLine() < $maxLines && !$csv->isEndOfFile()) {
            $raw = $csv->readRaw();
            if (false === $raw) {
                continue; // This is probably an empty line, no harm to skip it
            }
            $splitCsv->writeRaw($raw);
        }
        $splitCsv->close();

        return $tmpFilePath;
    }
@param CsvFile $csv
@param int     $maxLines

@throws \RuntimeException
@throws \LogicException
@throws \UnexpectedValueException

@return string