dqwh26750 2009-12-12 19:12
浏览 39
已采纳

显示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!

  • 写回答

1条回答 默认 最新

  • douxiuar885064 2009-12-12 19:16
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致