PHP code example of linio / lock
1. Go to this page and download the library: Download linio/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/ */
linio / lock example snippets
use Linio\Lock\Lock;
// Define options for the forced release.
$options = getopt('f', ['force']);
// Create the lock instance.
$lock = new Lock('lock_name');
// Create the lock file with the pid inside.
$lock->acquire();
// Check if the application is locked.
if ($lock->isLocked()) {
// If the '-f' or '--force' cli option is set.
if (isset($options['f']) || isset($options['force'])) {
// Release the lock killing the running process.
$lock->forceRelease();
} else {
// Do not execute the application if it is locked.
die('Another instance of the application is running');
}
}
Application::run();
// Release the lock after the execution
$lock->release();