如何在 PHP Shell 脚本中显示文件下载进度?
我有一个 php shell 脚本,可以下载一个大文件,在下载过程中能够在 shell 中看到下载进度有点奢侈,任何人都知道如何实现这一点(或者至少指出我的方向是正确的!)
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试在下载时轮询已下载文件的文件大小,并将其与您请求的文件的文件大小进行比较。
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.
这似乎有效(出乎意料!)
This seemed to work (unexpectedly!)
读取文件的标头以获取文件的大小(如果该信息可用)。然后跟踪您已下载的数量,这将为您提供百分比。
您如何执行此操作取决于您使用的库/函数。
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.