Jobby\Helper::getLockLifetime PHP Метод

getLockLifetime() публичный Метод

public getLockLifetime ( string $lockFile ) : integer
$lockFile string
Результат integer
    public function getLockLifetime($lockFile)
    {
        if (!file_exists($lockFile)) {
            return 0;
        }
        $pid = file_get_contents($lockFile);
        if (empty($pid)) {
            return 0;
        }
        if (!posix_kill(intval($pid), 0)) {
            return 0;
        }
        $stat = stat($lockFile);
        return time() - $stat["mtime"];
    }

Usage Example

Пример #1
0
 /**
  * @covers ::getLockLifetime
  */
 public function testGetLocklifetime()
 {
     $this->helper->acquireLock($this->lockFile);
     $this->assertEquals(0, $this->helper->getLockLifetime($this->lockFile));
     sleep(1);
     $this->assertEquals(1, $this->helper->getLockLifetime($this->lockFile));
     sleep(1);
     $this->assertEquals(2, $this->helper->getLockLifetime($this->lockFile));
     $this->helper->releaseLock($this->lockFile);
 }
All Usage Examples Of Jobby\Helper::getLockLifetime