显示PHP脚本的完整百分比

显示PHP脚本的完整百分比

问题描述:

I have a PHP script that takes about 10 minutes to complete.

I want to give the user some feedback as to the completion percent and need some ideas on how to do so.

My idea is to call the php page with jquery and the $.post command.

Is there a way to return information from the PHP script without ending the script?

For example, from my knowledge of this now, if I return the variable, the PHP script will stop running.

My idea is to split the script into multiple PHP files and have the .post run each after a return from the previous is given.

But this still will not give an accurate assessment of time left because each script will be a different size.

Any ideas on a way to do this?

Thanks!

我有一个大约需要10分钟才能完成的PHP脚本。 p>

我想向用户提供一些关于完成百分比的反馈,并且需要一些关于如何操作的想法。 p>

我的想法是用jquery和$ .post命令调用php页面。 p>

有没有办法在不结束脚本的情况下从PHP脚本返回信息? p>

例如,根据我对此的了解,如果我 返回变量,PHP脚本将停止运行。 p>

我的想法是将脚本拆分为多个PHP文件,并在给出前一个返回之后运行.post。 p>

但是这仍然无法准确评估剩余的时间,因为每个脚本的大小都不同。 p>

关于如何做到这一点的任何想法? p>

谢谢! p> div>

You can echo and flush() output, but that's suboptimal and rather fragile solution.

For long operations it might be good idea to launch script in the background and store/updte script status in shared location.

e.g. you could lanuch script using fopen('http://… call, proc_open PHP CLI process or even just openg long-running script in an <iframe>.

You could store status in the database or in shared memory (using apc_store()).

This will let user to check status of the script at any time (by refreshing page, or using AJAX) and user won't lose track of the script if browser's connection times out.

It also lets you avoid starting same long script twice.