Jobby\Helper::releaseLock PHP Method

releaseLock() public method

public releaseLock ( string $lockFile )
$lockFile string
    public function releaseLock($lockFile)
    {
        if (!array_key_exists($lockFile, $this->lockHandles)) {
            throw new Exception("Lock NOT held - bug? Lockfile: {$lockFile}");
        }
        if ($this->lockHandles[$lockFile]) {
            ftruncate($this->lockHandles[$lockFile], 0);
            flock($this->lockHandles[$lockFile], LOCK_UN);
        }
        unset($this->lockHandles[$lockFile]);
    }

Usage Example

Example #1
0
 /**
  *
  */
 public function run()
 {
     $lockfile = $this->getLockFile();
     try {
         $this->checkMaxRuntime($lockfile);
     } catch (Exception $e) {
         $this->log("ERROR: " . $e->getMessage());
         $this->mail($e->getMessage());
         return;
     }
     if (!$this->shouldRun()) {
         return;
     }
     $lockAcquired = false;
     try {
         $this->helper->acquireLock($lockfile);
         $lockAcquired = true;
         if ($this->isFunction()) {
             $this->runFunction();
         } else {
             $this->runFile();
         }
     } catch (InfoException $e) {
         $this->log("INFO: " . $e->getMessage());
     } catch (Exception $e) {
         $this->log("ERROR: " . $e->getMessage());
         $this->mail($e->getMessage());
     }
     if ($lockAcquired) {
         $this->helper->releaseLock($lockfile);
         // remove log file if empty
         $logfile = $this->getLogfile();
         if (is_file($logfile) && filesize($logfile) <= 0) {
             unlink($logfile);
         }
     }
 }
All Usage Examples Of Jobby\Helper::releaseLock