dongzha5934 2015-05-06 06:33
浏览 71
已采纳

PHPExcel for循环超时

I have this code where I want to set from 3 to 333 to have a certain row height at every 30 interval, meaning at row 3, 33, 63, 93 up till 333:

for ($i=3; $i<340; $i+30){
        $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(57);
}

But when I click on controller actionGenerate(), it doesn't generate and timeouts me after 30 seconds. Can I know why isn't it generating?

If I were to use the manual way, as in doing line by line, PLUS having so many different kinds of settings, I'd be exhausted.

  • 写回答

1条回答 默认 最新

  • dswg47377 2015-05-06 07:24
    关注

    PHP limits the execution time of any script. The default time is 30 seconds. Your script probably takes longer than 30 seconds to execute.

    Set your set_time_limit to 0. This will set it to unlimited.

    like this:

    set_time_limit(0);
    for ($i=3; $i<340; $i+=30){ // <--- here was your problem
            $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(57);
    }
    

    And try again.

    Info about set_time_limit in the docs

    -- edit--

    The problem was in the for loop.

    $i + 30 adds 30 to $i but it does not assign it. It should be $i +=30

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看