[英]Error loading csv file: Huge text node out of memory
当使用PHPExcel加载38MB .csv文件时,我得到了一个huge text node: out of memory
不足错误,即使我将php memory_limit
设置为1024M。
知道如何加载大型.csv文件吗?
错误
Error loading file "data.csv": Warning: DOMDocument::loadHTMLFile(): xmlSAX2Characters: huge text node: out of memory in /var/www/site/data.csv, line: 264094 in /var/www/site/vendor/CodePlex/PHPExcel/PHPExcel/Reader/HTML.php line 458
PHP代码
ini_set('memory_limit', '1024M');
$inputFileName = '/var/www/site/data.csv';
$phpExcel = new PHPExcel;
// Read your Excel workbook
try
{
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
}
catch(Exception $e)
{
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
php.ini
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M
您可以使用fgetcsv并逐行加载csv。
$file = '/path/filename.csv';
$f = fopen($file, 'rb');
while( $cols = fgetcsv($f) )
{
// $cols[0]; // first column of the current row
}
fclose($f);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.