note 129596 added to function.usleep

From: Date: Wed, 19 Jun 2024 16:19:43 +0000
Subject: note 129596 added to function.usleep
Groups: php.notes 
Request: Send a blank email to php-notes+get-221384@lists.php.net to get a copy of this message
I've found out the hard way that ZipArchive::addFile() works asynchronously and returns immediately. If you want to time adding a file to a zip 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, 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/function.usleep.php Edit -- https://main.php.net/note/edit/129596 Del: integrated -- https://main.php.net/note/delete/129596/integrated Del: useless -- https://main.php.net/note/delete/129596/useless Del: bad code -- https://main.php.net/note/delete/129596/bad+code Del: spam -- https://main.php.net/note/delete/129596/spam Del: non-english -- https://main.php.net/note/delete/129596/non-english Del: in docs -- https://main.php.net/note/delete/129596/in+docs Del: other reasons-- https://main.php.net/note/delete/129596 Reject -- https://main.php.net/note/reject/129596 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221384) next »