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 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序