duanchuaiwan0063 2011-10-30 22:03
浏览 308
已采纳

在foreach循环中运行函数时进度条

I have a foreach loop that calls a function to set values to an array. Sometimes it takes hours to complete depending on how many times it has to run thru the function to complete.

What I would like to have is a progress bar or at least a 1/1000 completed type progress indicator.

Is this possible? If so how could I implement this into my code? Would it be in the function or in the foreach loop? Been researching and found some examples using for and $i++ but I am not really sure how to implement that since I am already using a foreach loop.

Thanks much.

 function scrape_amazon($links) {
 //my code runs here to set all values in $ret array.
 }


 foreach($links as $link) {
$ret = scrape_amazon($link);
 }
  • 写回答

2条回答 默认 最新

  • dtjpnd7517 2011-10-31 03:52
    关注

    PHP probably isn't really the right tool for this task, however what you could do is:

    • Launch the slow code as a background process, and output progress to a file.
    • Have a PHP script that polls that file for progress information (either by page refresh or AJAX)

    Launching the background process can be done in several ways, including:

    • Launch via cron every 60 seconds, and poll for new jobs spooled in some readable area
    • Launch via a fork/exec mechanism from a web page
    • Launch as a daemon at system startup

    It will take some effort to avoid problems with multiple executions and/or overlap.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?