Skip to content

Instantly share code, notes, and snippets.

@phith0n
Last active July 22, 2021 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phith0n/38aa9330b750e1dab4bec7f529a42c7b to your computer and use it in GitHub Desktop.
Save phith0n/38aa9330b750e1dab4bec7f529a42c7b to your computer and use it in GitHub Desktop.
progress enabled file server
<?php
set_time_limit(0);
$filename = 'bigfile.txt';
$f = fopen($filename, 'r');
$i = 0;
$chunk = 2;
$each = 100 / (filesize($filename) / $chunk);
while (true) {
if (feof($f)) {
break;
}
$data = fread($f, $chunk);
error_log("file download progress: " . ($i * $each) . "%");
$i++;
echo $data;
sleep(1);
}
fclose($f);
@phith0n
Copy link
Author

phith0n commented Jul 22, 2021

正常使用删掉sleep即可。chunk可以改大点。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment