PHP code example of swordev / mutex

1. Go to this page and download the library: Download swordev/mutex 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/ */

    

swordev / mutex example snippets


use Swordev\Mutex\FileMutex;

$mutex1 = new FileMutex('key');
$mutex2 = new FileMutex('key');

$mutex1->readLock(); // true
$mutex2->writeLock(); // false

$mutex1->unlock(); // true
$mutex2->writeLock(); // true

use Swordev\Mutex\FileMutex;

$mutex = new FileMutex('key');
$mutex->writeLock(5000);

use Swordev\Mutex\FileMutex;

class Foo {
	function method() {
		$mutex = new FileMutex(__CLASS__ . '|' . __FUNCTION__);
		$mutex->writeLock();
		// ...
	}
}

use Swordev\Mutex\MutexFactory;

$mutex = new MutexFactory::create(FileMutex::class, 'key');