PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 4, 2022

[FIXED] How to optimal phpExcel when it's very slow?

 October 04, 2022     php, phpexcel, symfony     No comments   

Issue

I am doing exporting excel file using phpExcel. I output 2000 rows and its execution time is about 10 seconds . The problem is that when I output 20,000 rows it gets error: ERROR TIME OUT . At first: max_execution_time = 30, I set it back to max_execution_time = 60 (This value is equal to the value on the main server). Now is there a way to minimize file export time, since the data is sometimes very large..Up to a few hundred thousand rows. Please help me. Thanks. Sorry my english is not good.

  • Here is my code :

         // array example
        // 20.000 rows
        $data = [
            [
                'name' => 'hello',
                'address' => 'usa',
                'birthday' => '2021-04-30'
            ],
            [
                'name' => 'hello',
                'address' => 'usa',
                'birthday' => '2021-04-30'
            ],
        ];
        // Sample processing code
        $exRow = 2;
        foreach ($data as $val) {
            for ($i = 0; $i < 12; $i++) { // set title
                $excel->getActiveSheet()->setCellValueByColumnAndRow($i, $exRow, $val);
            }
        }
        header('Content-type: application/vnd.ms-excel');
        header('Content-Disposition: attachment; filename="data.xls"');
        PHPExcel_IOFactory::createWriter($excel, 'Excel2007')->save('php://output');

Solution

you just need to increase max_execution_time in php.ini file. if you don't access to do this just can make a php.ini or user.ini and put this text on there

max_execution_time=500

also you can use yield key to add excel row. this is help you render excel rows by lazy rendering

visit this link



Answered By - mohammad13
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing