diff --git a/src/Command/DaemonCommand.php b/src/Command/DaemonCommand.php index 66931d6..629b6e3 100644 --- a/src/Command/DaemonCommand.php +++ b/src/Command/DaemonCommand.php @@ -50,7 +50,7 @@ class DaemonCommand extends Command throw new \InvalidArgumentException('Time limit has incorrect value'); } $jobRepo->unlockJob(); - file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', posix_getpid()); + file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', time()); while(1) { if($endofscript !== false && time() > $endofscript) break; @@ -86,6 +86,7 @@ class DaemonCommand extends Command } } $this->doctrine->getManager()->clear(); + file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', time()); $maxwait = time() + 30; $nextrun = $jobRepo->getTimeOfNextRun(); diff --git a/src/Service/DaemonHelpers.php b/src/Service/DaemonHelpers.php index 0eb5bdc..a3a5513 100644 --- a/src/Service/DaemonHelpers.php +++ b/src/Service/DaemonHelpers.php @@ -14,8 +14,8 @@ class DaemonHelpers */ public static function isProcessRunning($pidFile = '/var/run/myfile.pid') { if (!file_exists($pidFile) || !is_file($pidFile)) return false; - $pid = file_get_contents($pidFile); - $return = posix_kill((int)$pid, 0); + $lasttick = file_get_contents($pidFile); + $return = ((int)$lasttick >= (time() - 30)); if (!$return) unlink($pidFile); return $return; }