【问题标题】:Delete a file if the timestamp is more than 20 minutes php如果时间戳超过 20 分钟 php 删除文件
【发布时间】:2016-10-09 07:06:57
【问题描述】:

如果时间戳超过 20 分钟,我正在尝试删除 $lockfile。

if (file_exists($lockfile) && time() - filemtime($lockfile) > strtotime("+20 minutes")) {
    // If lockfile is alive for more than 20 minutes, unlink it
    unlink($lockfile);
}

我不知道为什么它不起作用。可能是我现在忽略的一些简单的事情。提前谢谢!

【问题讨论】:

    标签: php strtotime file-exists filemtime


    【解决方案1】:

    strtotime("+20 minutes")会返回20分钟后日期的时间戳,大于两个时间戳之差。你应该在 20 分钟内替换它,所以:

    if (file_exists($lockfile) && time() - filemtime($lockfile) > 20*60) {
        // If lockfile is alive for more than 20 minutes, unlink it
        unlink($lockfile);
    }
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 2018-07-03
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      相关资源
      最近更新 更多