I am trying to delete a $lockfile if the timestamp is more than 20 minutes.
if (file_exists($lockfile) && time() - filemtime($lockfile) > strtotime("+20 minutes")) {
// If lockfile is alive for more than 20 minutes, unlink it
unlink($lockfile);
}
I can not figure out why it is not working. Probably something simple that I am overlooking right now. Thank you in advance!
strtotime("+20 minutes")
will return the timestamp of the date in 20 minutes from now, which is larger that the difference of the two timestamps. You should replace it by the time 20 minutes take in seconds, so:
if (file_exists($lockfile) && time() - filemtime($lockfile) > 20*60) {
// If lockfile is alive for more than 20 minutes, unlink it
unlink($lockfile);
}
That should do the trick.