- if (!is_bool($lock)) {
- $pid = (int)$lock;
-
- // When the process id isn't used anymore, we can safely claim the lock for us.
- // Or we do want to lock something that was already locked by us.
- if (!posix_kill($pid, 0) || ($pid == getmypid())) {
- $lock = false;
+ // When we do want to lock something new
+ if (is_null($lock)) {
+ // At first initialize it with "0"
+ $this->cache->add($cachekey, 0);
+ // Now the value has to be "0" because otherwise the key was used by another process meanwhile
+ if ($this->cache->compareSet($cachekey, 0, getmypid(), $ttl)) {
+ $got_lock = true;
+ $this->markAcquire($key);