reduce feof() calls (#1041)

micro-optimization: when doing large file copies, this will reduce the number of feof() calls. for example, if copying 100MB, this will save approximately 25,599 feof() calls (255 feof() calls for every MB) - also feofs() may do an actual syscall, and syscalls are relatively expensive/time-consuming.
This commit is contained in:
divinity76 2023-05-15 06:23:25 +02:00 committed by GitHub
parent dabc4ea36e
commit f7a2f77008
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -971,7 +971,15 @@ if (!empty($_FILES) && !FM_READONLY) {
if ($in) {
if (PHP_VERSION_ID < 80009) {
// workaround https://bugs.php.net/bug.php?id=81145
while (!feof($in)) { fwrite($out, fread($in, 4096)); }
do {
for (;;) {
$buff = fread($in, 4096);
if ($buff === false || $buff === '') {
break;
}
fwrite($out, $buff);
}
} while (!feof($in));
} else {
stream_copy_to_stream($in, $out);
}