How to Solve phpExcel Error: ERR_INVALID_RESPONSE

1. Occurrence scenario

  1. In thinkphp framework using phpoffice/phpexcel, exporting Excel tables directly to the browser for download, the error is reported: ERR_INVALID_RESPONSE
  2. Note: The export is fine in the local windows environment, but the problem only occurs in the online Linux environment.
  3. Screenshot of the problem.

2. Find a solution

1. Online solutions

1) Buffer problem

calling ob_clean() before calling save(“ php://output "), part of the code is as follows:

        ob_clean(); //Emptying the cache

        // final output via browser
        $fn = "The name of the file (" . date("Y.m.d") . ").xls"; // the name of the file to be saved
        header('Content-Type: application/vnd.ms-excel; charset=utf-8');
        header("Content-Disposition: attachment;filename={$fn}");
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;

2) Error is reported in line 581 of factory581, and break is deleted

Error in factory581 line, delete break;

PHPExcel\Calculation\Functions.php file, remove break at line 581

our phoffice/phpexcel is installed by composer. We have to change the source code every time we update it. It is not recommended to modify the source code. Even if it can solve the problem, it will not be adopted

2. My solution to this problem is to install the zip extension under Linux

[solution] my problem is that Linux lacks the zip extension. You can install it~

3. Zip extension

PHP under windows (my version is 7.3.3) has its own zip extension, and there is no directory_zip.dll file under the php/ext path, as shown in the figure

PHP under Linux does not have zip extension installed

Read More: