睡眠超时PHP无法正常工作

时间:2016-01-21 20:18:50

标签: php

我有一个每晚22:00执行的cronjob。 我从表中获取所有行,并且对于每一行,我执行一个执行其他行的函数。

但是其中一个功能有时真的很慢而且卡住了。所以,我需要等待一段时间,然后一遍又一遍地执行,最终工作,然后我转到下一行。

我正在尝试使用set_time_limit和sleep,但它不起作用,该功能停留在“重”功能上。为什么呢?

public function my_job(){
  $rows = get_rows();
  foreach($rows as $row){
     $executed=false;
     while(!$executed){
        set_time_limit(10); // just for test 10s timeout
        if ($this->execute_my_functions($row)){ // this function return true at the end
            $executed = true;
        }
        else{
            sleep(10); // test
        }
     }
  }
}

0 个答案:

没有答案