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

PHP - sleep() cannot continue execute after time has passed

目前,我在我的 PHP 脚本中实现了 sleep() 以暂停执行 15 分钟,以便在继续执行脚本之前为其他任务完成提供一些缓冲。

<?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);

?>

当从客户端调用 PHP 时,进程将登录 "pre_sleep.log" 并且在脚本完成之前将登录 "done.log"。但是,根据我写的日志,我注意到一些执行即使已经过去 15 分钟也不会继续。该进程已在 "pre_sleep.log" 中登录,其中 "done.log" 找不到相同的进程。

有没有可能15分钟内进程被别人kill掉了?这种情况的发生似乎非常随机,因为大多数进程都记录在两个日志文件中,但有些只出现在一个日志文件中。

进程有可能在休眠后(甚至在休眠前)被关闭。

我的最佳猜测是,您的 PHP 超时正在发挥作用。将以下内容放在脚本文件的顶部。

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

它将允许脚本 运行 永远