note 129597 added to ziparchive.addfile

From: Date: Wed, 19 Jun 2024 16:21:47 +0000
Subject: note 129597 added to ziparchive.addfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-221385@lists.php.net to get a copy of this message
As others have pointed out ZipArchive::addFile() is asynchronous. If you want to restrict the time when adding a large number of files this is the way to do it: <?php //$files is an array with a horrendous amount of filenames. //$fileCount the total number of files in $files e.q. count($files) //$fileIndex is the file you want to start with for( $fileIndex = 1, $start = hrtime( true ); $fileIndex < $fileCount and $secondsElapsed < 5.0; $fileIndex++ ) { $currentfile = $files[ $fileIndex ]; if( file_exists( $currentfile ) ) { $zip->addFile( $currentfile ); usleep(1); $secondsElapsed = ( hrtime( true ) - $start ) / 1e+9; } } ?> this will keep on adding files until the time out (5.0s) arises. Without usleep(1) it will just continue until the max_excecution_time is reached. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 83.97.87.43) ---- Manual Page -- https://php.net/manual/en/ziparchive.addfile.php Edit -- https://main.php.net/note/edit/129597 Del: integrated -- https://main.php.net/note/delete/129597/integrated Del: useless -- https://main.php.net/note/delete/129597/useless Del: bad code -- https://main.php.net/note/delete/129597/bad+code Del: spam -- https://main.php.net/note/delete/129597/spam Del: non-english -- https://main.php.net/note/delete/129597/non-english Del: in docs -- https://main.php.net/note/delete/129597/in+docs Del: other reasons-- https://main.php.net/note/delete/129597 Reject -- https://main.php.net/note/reject/129597 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221385) next »