src/Fuz/Component/SharedMemory/SharedMemory.php
public function lock($timeout = 0, $interval = 50000)
    {
        if ((!is_numeric($timeout)) || ($timeout < 0))
        {
            throw new \Exception("Lock timeout should be an integer greater or equals to 0.");
        }

        if ((!is_numeric($interval)) || ($interval < 5000))
        {
            throw new \Exception("Lock check interval should be an integer greater or equals to 5000.");
        }

        $this->storage->openWriter();

        $object = $this->getObjectSafely('openWriter');
        $object->setLocked(true);
        $object->setTimeout($timeout);
        $object->setInterval($interval);

        $this->lock = true;
        $this->storage->setObject($object);
        $this->storage->close();
    }
public function lock($timeout = 0, $interval = 50000)
    {
        if ((!is_numeric($timeout)) || ($timeout < 0))
        {
            throw new \Exception("Lock timeout should be an integer greater or equals to 0.");
        }

        if ((!is_numeric($interval)) || ($interval < 5000))
        {
            throw new \Exception("Lock check interval should be an integer greater or equals to 5000.");
        }

        $this->storage->openWriter();

        $object = $this->getObjectSafely('openWriter');
        $object->setLocked(true);
        $object->setTimeout($timeout);
        $object->setInterval($interval);

        $this->lock = true;
        $this->storage->setObject($object);
        $this->storage->close();
    }
public function lock ( $ timeout = 0 , $ interval = 50000 ) { if ( ( ! is_numeric ( $ timeout ) ) || ( $ timeout < 0 ) ) { throw new \ Exception ( "Lock timeout should be an integer greater or equals to 0." ) ; } if ( ( ! is_numeric ( $ interval ) ) || ( $ interval < 5000 ) ) { throw new \ Exception ( "Lock check interval should be an integer greater or equals to 5000." ) ; } $ this -> storage -> openWriter ( ) ; $ object = $ this -> getObjectSafely ( 'openWriter' ) ; $ object -> setLocked ( true ) ; $ object -> setTimeout ( $ timeout ) ; $ object -> setInterval ( $ interval ) ; $ this -> lock = true ; $ this -> storage -> setObject ( $ object ) ; $ this -> storage -> close ( ) ; }
Locks synchronized variable to the current process.

This is useful to avoid concurrent accesses, such as :

if (is_null($shared->check)) {
$shared->data = "something";
}

In the example above, the condition can be true for several processes
if $shared->check is accessed simultaneously.

@access public
@param int $timeout Define how many seconds the shared variable should be locked (0 = unlimited)
@param int $interval Microseconds between each lock check when a process awaits unlock
@return self
@throws \Exception
Locks synchronized variable to the current process .