Context
In a legacy app I am profiling a script that archives files in a zip. At the moment it takes about 30-35 seconds to add 55MB (~450 files) to a zip archive on a locally-running VM. I was hoping to figure out where I might improve that via profiling. The app runs on PHP 7.3 (it doesn't function on 8.x unfortunately) and Xdebug 3.1.6 is the latest version that supports this; the app includes a version of pclzip for creating archives, which I thought I would profile in comparison to native PHP zip handling to see if there is a substantial difference.
I've written a functional test using Selenium to roughly measure the archive time, and both approaches take roughly the same time, ~30-35 seconds.
kcachegrind output
Xdebug produces a breakdown of time spent and a call graph as expected for pclzip:
However Xdebug doesn't show the same time breakdown for native zip handling (ZipArchive):
Interestingly, the cachegrind files produced are of substantially-different sizes too:
$ ls -lh cachegrind.out.??.gz
-rw-r--r-- 1 bertieb bertieb 32M Jan 5 12:06 cachegrind.out.23.gz
-rw-r--r-- 1 bertieb bertieb 231K Jan 5 12:09 cachegrind.out.26.gz
(cachegrind.out.23.gz is the pclzip profile, cachegrind.out.26.gz is ZipArchive)
Question
What is the reason for this difference? I would expect to see similar time breakdowns and call graphs for both approaches. I am quite new to Xdebug, and searches didn't shed any light on this discrepancy.
Test code
The zip-creating/updating code for existing pclzip code:
// in a loop
$archive = new PclZip ($zipfilename);
$archive->add ($filename, PCLZIP_OPT_REMOVE_PATH, $removedir);
// loop continues
Create/update code for ZipArchive:
// also in loop
$archive = new ZipArchive();
$zipres = $archive->open($documentName, ZipArchive::CREATE);
if ($zipres) {
$storename = substr($filename, strpos($filename, "upload/"));
$archive->addFile($filename, $storename);
$archive->setCompressionName($storename, ZipArchive::CM_STORE); // contents not very compressible
// $archive->close(); // ← not performed here as slows down script by ⅙ to ⅓, deferred until after loop instead
}
// loop continues
// in cleanup
if ($archive) $archive->close();



