I'm running PHP 5.6.3. One of my professional project includes a dezip function :
// ZIP file to extract
$my_file = "repository.zip";
$zip = new ZipArchive;
if ($zip->open($my_file) === TRUE)
{
//Unpack all files from zip
$zip->extractTo($this->target_directory);
}
$zip->close();
... which is processed on a big ZIP file (~300Mo).
I made many excution time benchmark and I found that the extractTo() function is more than 90%/95% (20sec.) of the total processing time ! Worst of all, the ZIP size is going to increase in the next weeks (maybe up to 500 Mo).
Is there a way to optimize this part of my script ? Knowing that I do have to extract all the files from the ZIP.
Thanks.
Is there a way to optimize this part of my script ?
No - its a single line of code, called once. It should be obvious that there is no way to optimize it.
I suspect what you really want to know is if you can get the file unzipped sonner - and that is a very different question.
the extractTo() function is more than 90%/95% (20sec.) of the total processing time
Of the elapsed time? CPU time? PHP execution time?
There may be scope for getting the results faster, but you are not asking the right questions. You are not going to get a solution here - we don't have access to your system to fix it for you.
Since you've told us nothing about the OS and hardware this sits on, we are further constrained in the advice we can give. Moving to a faster CPU might help - but based on the information you've provided we don't know if its the CPU or the storage I/O which is the bottleneck here. How you make the whole system go faster would fill a large book (I know, I've written one).
Doing the extraction outside of PHP might help.
Using a different compression algorithm might help.
Creating multiple files and unzipping them in parallel would probably help.
....but you've also told us nothing about the constraints here.