Is memory running out on your server or doesn’t allow sending the final result to the client? If it just doesn't have enough memory, run zip on the file system instead. You can execute system commands in PHP with
system("...command...");
Thus, you can, based on the user's choice, aggregate the selected files in a temporary directory (using a system call to copy files), and then pin a temporary directory (using a system call to call pkzip), and then ask PHP to send a temporary file to the client, after causing your PHP script to remove it.
Thus, zipping does not consume memory in your PHP application.
source share