脚本宝典收集整理的这篇文章主要介绍了php – 读取大文件时出现内存不足错误,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$target = '../uploads/'.$f; $handle = foPEn($target,"r"); $data = fgetcsv($handle,","); $rows = array(); while ($data !== FALSE) { $rows[] = $data; } fclose($handle); if (count($rows)) { foreach ($rows as $key => $value) { echo $value; } }
每次我尝试运行我的脚本时都会收到此错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes)
$data = fgetcsv($handle,"); $rows = array(); while ($data !== FALSE) { $rows[] = $data; }
一次调用fgetcsv从$handle中读取一行.你需要把fgetcsv放在循环条件中:
$handle = fopen($target,"); while (($row = fgetcsv($handle,")) !== FALSE) { // Example insert - obvIoUsly use PRepared statements/escaping/another DAL $db->query("INSERT INTO tbl (columns..) VALUES ({$row[0]},{$row[1]} ... )"); }
以上是脚本宝典为你收集整理的php – 读取大文件时出现内存不足错误全部内容,希望文章能够帮你解决php – 读取大文件时出现内存不足错误所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。