PHPExcel Load Files More Than 15 seconds

2019-09-03 08:44发布

问题:

I'm using PHPExcel version 1.7.9.

Here is my PHP code :

        $temp_name = $_FILES['upload']['tmp_name'];
        $fname = $_FILES['upload']['name'];
        $transfer = move_uploaded_file($temp_name,TEMP_DIR.$fname);
        $file_location = TEMP_DIR.$fname;
        $inputFileType = PHPExcel_IOFactory::identify($file_location);
        $objReader = PHPExcel_IOFactory::createReader($inputFileType);
        $objReader->setReadDataOnly(true);
        $objPHPExcel = $objReader->load($file_location);

for each line of code above I echo time taken to produce the output


startup Pageload in 0.0272 seconds
upload file Pageload in 0.0408 seconds
Identify File Pageload in 0.0612 seconds
Create Reader Pageload in 0.0613 seconds
Set Read Data OnlyPageload in 0.0613 seconds
File read Pageload in 17.3884 seconds

my question is, why

$objPHPExcel = $objReader->load($file_location);

take 17.3884 seconds to load?

Other information :

  • MS Excel 2007
  • Size 384kb
  • Maximum Column - AF
  • Maximum Row = 184 row

回答1:

The same reason why phpexcel needs massive amounts of memory when writing a large file to disc...

A lot of data exists in excel documents, varying from content, formulae, conditional markup, markup, references, cell sizes, etc...

For each cell it has to be properly analysed, interpreted, matched with corresponding values within phpexcel.

It's the conversion proces that is the most timeconsuming and memory intensive.

You have 32 x 184 columns of data = 5888 cells that have to be interpreted = 0.002953 seconds per table cell, that is 2.9ms for a table cell.

Considering all the data crunching and variable happenings I find that pretty fast.

If you really want speed you'll need to write your own c(++) library and load that into php, then you can get a real speed boost.