douhuang7263 2013-02-18 16:05 采纳率: 100%
浏览 48

PHP sleep()函数在一段时间后查杀脚本

I am experiencing a problem when using sleep() function in php for a long period of time, if i test the following code all runs perfectly:

<?php

set_time_limit(0);

$i = 0;

while($i < 10) {

    echo $i.'<br />';

    if($i == 5){        
        echo 'sleeping 5 secs<br />';
        sleep(5);   
        echo 'waking up<br />';
    }

    $i++;
}

?>

*****OUTPUT****

0
1
2
3
4
5
sleeping 5 secs
waking up
6
7
8
9

*****OUTPUT****

It sleeps 5 seconds and after that the "waking up" is echoed without problems, but, if I raise the amount of seconds the script is sleeping to lets say 15 minutes the output is the following:

*****OUTPUT****

0
1
2
3
4
5
sleeping 900 secs //(15 mins)

*****OUTPUT****

The script appears to be killed after 15 minutes of sleeping!!, what could be causing this? note that I set the max_execution_time flag to infinite with set_time_limit(0); at the top of the script.

I will appreciate any help, thanks!

  • 写回答

2条回答 默认 最新

  • dongshan3759 2013-02-18 16:11
    关注

    Even the webserver (Apache, IIS, ...) has a timeout setting, try to check your many has 300sec as default).

    Moreover be carefull about set_time_limit. From the manual: 'This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.'

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?