Answer the question
In order to leave comments, you need to log in
Asynchronous work ZipArchive (::addFromString) loses files, how to win?
Input:
OS: Debian 9
PHP: v7.4
There is a directory with ~1KK {unixtime}.json files up to 1Mb in size.
I do renaming of files with its internal contents changing, and then I try to pack them all into one archive using the addFromString method.
The essence of the problem is that when using the ZipArchive methods asynchronously, I get the necessary archive at the output, but only with the last processed file within the framework of asynchrony (To be completely precise, N / t files get into the archive, where N is the total files to be added , t - number of processing threads)
I give below a simplified scheme of work ($dir,$newFileName, $stringData are defined at this point):
$za = new \ZipArchive();
($za->open($zipFile, \ZipArchive::CREATE) !== TRUE) {
throw new \Exception('Cannot create a zip file');
}
$arFile = $dir . '/' . $newFileName . '.json';
$result = $za->addFromString($arFile, $stringData);
$error = $za->getStatusString( );
$arIndex = $za->locateName($arFile);
$arInfo = $za->statName($arFile);
$closeResult = $za->close();
var_dump($error, $arIndex, $arInfo, $closeResult);
Answer the question
In order to leave comments, you need to log in
Well, let's turn to the documentation and try to understand at what point changes occur in the final file:
ZipArchive::close — Close opened or created archive and save changes. This method is automatically called at the end of the script.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question