Use PHP ZipArchive to download small compressed packages. Today, I encountered a 404 error of over 150M. The first thing I thought of is that the file size exceeded the default settings of PHP. There are two ways to modify it:
:memory_limit
memory_limit sets memory limits. If you use readfile() to read the file, it will be related to this. Just modify this value and save it and restart php-fpm.
php download file size setting PHP
memory_limit = 128M
Last remember: service php-fpm restart
ini_set
The value used by PHP ini_set takes effect when the function is executed, so we can directly use it to modify the memory execution size. If some friends use virtual space, this function is a savior.
PHP Setting Value PHP
ini_set('memory_limit', '512M');
Complete example:
PHP
set_time_limit(0); ini_set('memory_limit', '512M'); header("Cache-Control: public"); header("Content-Description: File Transfer"); header('Content-disposition: attachment; filename=' . basename($zipfile)); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); header('Content-Length: ' . filesize($zipfile)); ob_clean(); flush(); @readfile($zipfile); unlink($zipfile);
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.