PHP code example of gabriel-peleskei / lock-file
1. Go to this page and download the library: Download gabriel-peleskei/lock-file 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/ */
gabriel-peleskei / lock-file example snippets
use GabrielPeleskei\LockFile\Exception\GeneralException;
use GabrielPeleskei\LockFile\Exception\IsLockedException;
use GabrielPeleskei\LockFile\LockFile;
try {
$locker = new LockFile(__DIR__ . '/.basic.lock', []);
$locker->start(); // throws if lock file exists
echo "Processing...\n";
// do whatever..
// with destructor called,
// lockfile should be removed at the end...
} catch (IsLockedException $e) {
echo "Locked: Process is locked!\n";
exit(1);
} catch (GeneralException $e) {
// possible write permission problems...
echo "EXCEPTION: {$e->getMessage()} ({$e->getCode()})\n";
exit(2);
}
exit;