doushang7209 2013-06-19 13:28
浏览 72
已采纳

在脚本之间实现共享变量或如何实现服务器端进度的正确方法?

I have a long job serving to fill a table in a db. This job may takes various time to finish. So, I need a progress bar. Just counting on the page is enough. As far I found several solutions:

  1. Using _SESSION. OK, it works on most of servers I used, but I have many problem with ERR_RESPONSE_HEADERS_TOO_BIG error on chrome and sometimes - "headers already sent" on some servers, caused by session_start/session_write_close called in a loop. I loved this method but now I have reject it
  2. Using kind of ob_start/ob_end_flush inside of the long operation's loop. This doesn't work. It just displays all buffered echo-ed messaged after the end of script.
  3. Using db to store a shared variable (not tried yet)
  4. Using separate (temporary) file. (not tried yet).

I have already implemented infrastructure: one script for long job (populating a table in db) and another one used by JS to read shared variable containing progress status. Both these scripts I called with jQuery .ajax method expecting the results in .done function.

Is there any other methods? It seems I will like to use 4) variant, but I want to know what is the usual practice for implementing progress bar.

Thanks:)

  • 写回答

3条回答 默认 最新

  • dongwen9947 2013-06-19 13:37
    关注

    Firstly, if you aren't already, I would run the PHP code as a separate process.

     <?php 
    
     exec('/usr/bin/php /Path/to/script.php  {$param1} {$param2} > /dev/null 2>/dev/null &'); 
    
     ?>
    

    I would then get this process to update a DB with its progress against the ID of the user, you could then use a ajax call inside a timeout function to get the status (how many DB writes complete, how many left, etc) from the DB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用