How to show file download progress in PHP Shell Sc

2019-08-29 12:04发布

问题:

I have a php shell script that downloads a large file, it would be a bit of a luxury to be able to see the progress of the download in shell while it's happening, anyone have any idea how this can be achieved (or at least point me in the right direction!)

Thanks!

回答1:

You could try to poll the filesize of the downloaded file as it's downloading, and compare it with the filesize of the file you requested.



回答2:

This seemed to work (unexpectedly!)

echo "wget '$feedURL'\n";
$execute = "wget -O ".$filePath." '$feedURL'\n";
$systemOutput = shell_exec($execute);
$systemOutput = str_replace( "\n", "\n\t", $systemOutput);
echo "\t$systemOutput\n";


回答3:

Read the header of the file to get the size of the file (if that information is available). Then keep track of how much you have downloaded and that will give you your percentage. How you might do that depends on what libraries/functions you are using.