Last active
July 22, 2021 04:16
-
-
Save phith0n/38aa9330b750e1dab4bec7f529a42c7b to your computer and use it in GitHub Desktop.
progress enabled file server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
正常使用删掉sleep即可。chunk可以改大点。