Skip to content

Commit

Permalink
reduce feof() calls (#1041)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
divinity76 committed May 15, 2023
1 parent dabc4ea commit f7a2f77
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,15 @@ function get_file_path () {
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);
}
Expand Down

0 comments on commit f7a2f77

Please sign in to comment.