How to show file download progress in PHP Shell Sc

2019-08-29 12:22发布

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!

3条回答
孤傲高冷的网名
2楼-- · 2019-08-29 12:29

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.

查看更多
神经病院院长
3楼-- · 2019-08-29 12:33

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.

查看更多
迷人小祖宗
4楼-- · 2019-08-29 12:39

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";
查看更多
登录 后发表回答