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

时间:2018-11-28 08:02:50

标签: php sleep

当前,我在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分钟内被其他人杀死?这似乎是非常随机的,因为大多数进程都记录在两个日志文件中,但有些仅出现在一个中。

1 个答案:

答案 0 :(得分:0)

有可能在睡眠后(甚至在睡眠之前)关闭该进程。

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

async.auto({
    // ...
}, 
function(err, results) {
    if (cb) {
        if (err) {
            cb(err);
            return;
        }
        try {
            fs.unlinkSync(configFile);
            fs.renameSync(downFileName, filePath);
        } catch (ex) {
            cb(ex);
            return;
        }
        cb(err, {msg:'success', path:filePath}, null);
    } else {
        // really, i wouldn't even bother fix this case and just make cb required.
    }
})

它将允许脚本永久运行

相关问题