Doc #80940 [NEW]: async function addFromString work incorrect

From: Date: Wed, 07 Apr 2021 19:00:44 +0000
Subject: Doc #80940 [NEW]: async function addFromString work incorrect
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18694@lists.php.net to get a copy of this message
From:             skuratovichalex at gmail dot com
Operating system: Debian 9
PHP version:      7.4.16
Package:          Zip Related
Bug Type:         Documentation Problem
Bug description:async function addFromString work incorrect

Description:
------------
The essence of the problem is that when using the ZipArchive methods
asynchronously, at the output I get the required archive, but only with
the last processed file within the framework of asynchrony (To be more
precise, the archive contains N / t files, where N is the total files to
be added , t is the number of processing threads)
PS-The initial presence of the archive does not change the situation.

Example: (6 files)
https://drive.google.com/file/d/1BAHn4iSElaADwfxQ_3_ZaTOmPKvggwH6/view?usp=sharing

Test script:
---------------
//one stream
$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);

Expected result:
----------------
file2
file1
file3
file4
string(8) "No error"
int(0)
array(8) {
  ["name"]=>
  string(17) "/order/file2.json"
  ["index"]=>
  int(0)
  ["crc"]=>
  int(0)
  ["size"]=>
  int(811758)
  ["mtime"]=>
  int(1617821517)
  ["comp_size"]=>
  int(811758)
  ["comp_method"]=>
  int(0)
  ["encryption_method"]=>
  int(0)
}
bool(true)
string(8) "No error"
int(0)
array(8) {
  ["name"]=>
  string(17) "/order/file3.json"
  ["index"]=>
  int(0)
  ["crc"]=>
  int(0)
  ["size"]=>
  int(811758)
  ["mtime"]=>
  int(1617821517)                                                       
                                                                        
                                                                 
  ["comp_size"]=>                                                       
                                                                        
                                                                 
  int(811758)                                                           
                                                                        
                                                                 
  ["comp_method"]=>                                                     
                                                                        
                                                                 
  int(0)                                                                
                                                                        
                                                                 
  ["encryption_method"]=>                                               
                                                                        
                                                                 
  int(0)                                                                
                                                                        
                                                                 
}                                                                       
                                                                        
                                                                 
bool(true)                                                              
                                                                        
                                                                 
string(8) "No error"                                                    
                                                                        
                                                                 
int(0)                                                                  
                                                                        
                                                                 
array(8) {
  ["name"]=>
  string(17) "/order/file4.json"
  ["index"]=>
  int(0)
  ["crc"]=>
  int(0)
  ["size"]=>
  int(811758)
  ["mtime"]=>
  int(1617821517)
  ["comp_size"]=>
  int(811758)
  ["comp_method"]=>
  int(0)
  ["encryption_method"]=>
  int(0)
}
bool(true)
string(8) "No error"
int(0)
array(8) {
  ["name"]=>
  string(17) "/order/file1.json"
  ["index"]=>
  int(0)
  ["crc"]=>
  int(0)
  ["size"]=>
  int(811758)
  ["mtime"]=>
  int(1617821517)
  ["comp_size"]=>
  int(811758)
  ["comp_method"]=>
  int(0)
  ["encryption_method"]=>
  int(0)
}
bool(true)


Actual result:
--------------
4 JSON-files in ZIP-archive.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80940&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80940&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80940&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80940&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80940&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80940&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80940&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80940&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80940&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80940&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80940&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80940&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80940&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80940&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80940&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80940&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80940&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80940&r=mysqlcfg


Thread (9 messages)

« previous php.doc.bugs (#18694) next »