phpspreadsheet版本:1.5.0
spout版本:2.7.3
在同样的环境下,运行代码,spout的在内存使用和时间花费上都占优,在phpspreadsheet读取失败的文档spout依然能正确完成读取。
spout代码
<?php ini_set('memory_limit', '2G'); var_dump(memory_get_usage()); var_dump(microtime()); $loader = include 'vendor/autoload.php'; use Box\Spout\Common\Type; use Box\Spout\Reader\ReaderFactory; $file = '20.xlsx'; $type = pathinfo($file); $type = strtolower($type["extension"]); if ($type === 'xlsx') { $type = Type::XLSX; } else { $type = Type::CSV; } try{ $reader = ReaderFactory::create($type); $reader->open($file); $reader->setTempFolder('/dev/shm/'); $iterator = $reader->getSheetIterator(); $iterator->rewind(); $sheet1 = $iterator->current(); $rowIter = $sheet1->getRowIterator(); $data = array(); foreach ($rowIter as $rowIndex => $row) { $data[] = $row; } var_dump(count($data)); }catch (\Exception $e){ return []; } var_dump(microtime()); var_dump(memory_get_usage()); var_dump(memory_get_peak_usage());
phpspreadsheet代码
<?php ini_set('memory_limit', '2G'); var_dump(memory_get_usage()); var_dump(microtime()); $loader = include 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\IOFactory; $file = '20.xlsx'; try { $spreadsheet = IOFactory::load($file); $data = $spreadsheet->getActiveSheet()->toArray('', true, true); $spreadsheet->disconnectWorksheets(); unset($spreadsheet); var_dump(count($data)); } catch (Exception $e) { var_dump($e->getMessage()); } var_dump(microtime()); var_dump(memory_get_usage()); var_dump(memory_get_peak_usage());