开发者

Showing percentage complete of PHP script

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 idea开发者_StackOverflow中文版s 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜