PHP code example of michel / lock

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

    

michel / lock example snippets


use Michel\Lock\Locker;
use Michel\Lock\Handler\FlockHandler;

$locker = new Locker(new FlockHandler());

if (!$locker->lock('nightly_import')) {
    echo "Already running.\n";
    exit(0);
}

runImport(); // only one process at a time runs this

$locker->unlock('nightly_import');

$locker->lock('counter', true); // blocks until the lock is free