Download the PHP package mouf/utils.common.lock without Composer
On this page you can find all versions of the php package mouf/utils.common.lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mouf/utils.common.lock
More information about mouf/utils.common.lock
Files in mouf/utils.common.lock
Package utils.common.lock
Short Description A simple package that provides functions to get a lock. Typically, you want to use locks when you want to be sure that 2 actions do not happen at the same time. For instance, if you regularly schedule cron tasks, you might want to be sure the last cron task finished before running the new one. A lock can help you do that.
License MIT
Homepage http://mouf-php.com/packages/mouf/utils.common.lock
Informations about the package utils.common.lock
Lock Manager
The LockManager package is a simple package that provides functions to get a lock. Typically, you want to use locks when you want to be sure that 2 actions do not happen at the same time. For instance, if you regularly schedule cron tasks, you might want to be sure the last cron task is finished before running a new one. A lock can help you do that.
The Lock class
The Lock class represents a lock. You can acquire a lock to lock the resource and release the lock to set it free. Of course, if the lock has been already acquired by another user, you won't be able to acquire it yourself. You can optionnaly wait for the lock to be freed by the other process to acquire it yourself.
Internally, locks are acquired by putting a lock on a "file" that is hidden in the temp
directory. When creating a Lock
instance in Mouf, you will therefore have to find a unique temp name
for that file.
If your PHP script crashes or exits without explicitly releasing the lock, the lock will be automatically released, so that other processes can use the lock.
Example
A first example: trying to acquire a lock without waiting
A second example: acquire a lock and wait if the lock is not available
Good practices
A good practice is to create the lock object via a dependency injection mechanism. This way, you can share instances of your lock accross services that require it. The Mouf framework let's you do that. Let's assume you create a "myLock" instance:
Your code to use the lock would look this: