doushu0591 2018-11-28 08:02
浏览 294
已采纳

PHP - sleep()在经过一段时间后无法继续执行

currently I implement the sleep() in my PHP script to pause the execution for 15 minutes to give some buffer for other tasks to finish before continue to execute the script.

<?php

------do something here-----

   file_put_contents("logs/pre_sleep.log", "$id sleep in $datetime", FILE_APPEND);

   sleep(900);    

----continue do something here----

   file_put_contents("logs/done.log", "$id done in $datetime", FILE_APPEND);

?>

When the PHP is called from client, the process will be logged in "pre_sleep.log" and before the script finish will be logged in "done.log". However, based on the log I write, I notice the some execution will not continue even has passed for 15 minutes. The process has been logged in "pre_sleep.log" where "done.log" couldn't find the same process.

Is it possible the process been killed by others within 15 minutes? This happens seem like very randomly, because most of the processes logged in both log files but some appear in only one.

  • 写回答

1条回答 默认 最新

  • dougan1465 2018-11-28 08:07
    关注

    It is possible the process gets shut down after the sleep (or even before the sleep).

    My best guess is, your PHP timeout is in play. Put the following at the top of your script file.

    set_time_limit(0);
    // or
    ini_set('max_execution_time', 0);
    

    It will allow for scripts to run forever

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

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀