PHP code example of mouf / utils.common.lock

1. Go to this page and download the library: Download mouf/utils.common.lock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mouf / utils.common.lock example snippets


// Let's create the lock instance
$lock = new Lock("my_lock_name");

// Try to acquire lock without waiting
try {
	$lock->acquireLock();
	// ... Do some stuff ...
	$lock->releaseLock();
} catch (LockException $e) {
	// The lock could not be acquired... Let's ignore this.
}

// Let's create the lock instance
$lock = new Lock("my_lock_name");

// Try to acquire lock and wait if the lock is not available
$lock->acquireLock(true);
// ... Do some stuff ...
$lock->releaseLock();


// You need to create an instance "myLock" of the Lock class in Mouf first.
$lock = Mouf::getMyLock();

// Try to acquire lock without waiting
try {
	$lock->acquireLock();
	// ... Do some stuff ...
	$lock->releaseLock();
} catch (LockException $e) {
	// The lock could not be acquired... Let's ignore this.
}