进度条实际发生了什么
我知道这是一个新手问题,但进度条实际发生了什么,它实际监控的是什么。
我认为理解它的唯一方法就是得到这个答案。
当我运行一段 php 代码时,如何获得一个进度条来监视它,同时它运行直到代码完成?
我见过的大多数进度条都是文件上传和下载。它是否监视浏览器在上传文件时发送的请求量,以便监视正在传输的字节?
有人可以让我更好地了解发生了什么吗?
我只是想要一个简单的进度条来监视我的 php 代码运行时的进度,所以说如果我运行这个简单的代码来备份网站文件和文件夹,我该怎么做呢???
<?php if ( isset($_POST['backup']) ) {
if(exec("cd {$_SERVER['DOCUMENT_ROOT']}/wp-content/plugins/s3bk/files;tar -cvpzf backup.tar ".get_option( 'isd-server')."")) { echo "done"; }
}
<form id="backup" method='post' action=''>
<?php if (function_exists('wp_nonce_field')) { wp_nonce_field('s3bk-updatesettings'); } ?>
<input type='submit' class="button" name='backup' value='backup'>
抱歉,这个菜鸟问题只是让我了解一下到底发生了什么???
谢谢
I know this is a rookie question but whats actually happening with a progress bar what is it actually monitoring.
I figure the only way to understand it is to get this answer.
when i run a piece off php code how can i get a progress bar to monitor it while it runs untill completion off the code??
most progressbars i have seen are file upload and download. is it monitoring the amount off requests the browser sends when upload the file so its monitoring the bytes that are being transfer?
Can someone please give me a better understanding off whats going on?
I just want a simple progress bar to monitor progress while my php code is running so say if i am running this simple code to backup a websites files and folders, how could i do this???
<?php if ( isset($_POST['backup']) ) {
if(exec("cd {$_SERVER['DOCUMENT_ROOT']}/wp-content/plugins/s3bk/files;tar -cvpzf backup.tar ".get_option( 'isd-server')."")) { echo "done"; }
}
<form id="backup" method='post' action=''>
<?php if (function_exists('wp_nonce_field')) { wp_nonce_field('s3bk-updatesettings'); } ?>
<input type='submit' class="button" name='backup' value='backup'>
sorry for the rookie question just really want to get my head around whats actually happening???
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法监视类似的事情 - 您正在从 PHP exec()ing 外部程序,因此当该外部进程处于活动状态时 PHP 被挂起。同样,tar 无法提前报告有多少工作要做,它只能报告已完成或当前正在执行的操作。
进度条的工作原理是
(已完成多少/还有多少待办事项)* 100
。如果事先不知道需要使用 tar 备份多少文件/字节,则无法计算完成百分比。You wouldn't be able to monitor something like that - you're exec()ing an external program from PHP, so PHP is suspended while that external process is active. As well, tar can't report in advance how much there is to do, it can only report on what it's done or is currently doing.
A progress bar works on the basis of
(how much is done / how much there is todo) * 100
. Without knowing in advance exactly how many files/bytes there are to back up with tar, you can't calculate a completion percentage.