How to show file download progress in PHP Shell Scripting?

感情迁移 提交于 2019-12-11 16:57:39

问题


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.



来源:https://stackoverflow.com/questions/1834678/how-to-show-file-download-progress-in-php-shell-scripting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!