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 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型