1. Go to this page and download the library: Download illchuk/illchuk-locker 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/ */
illchuk / illchuk-locker example snippets
'modules' => [..., 'IllchukLock', ...];
// in controller
$locker = $this->getServiceLocator()->get('IllchukLock');
// term?
$term = new DateTimeUnit(2, 'weeks'); // or
$term = new DateTimeEnd(new DateTime('+2 weeks'));
if ($locker->takeLock('BiWeeklyReport', $term)) {
// lock is taken atomically, made for 2 weeks: safe to do your work
}
else {
// locked from before: leave it alone & perhaps try again later
}
/**
* N.B. May throw \IllchukLock\Exception\PhantomLockException, when
* lock is reported to be set but upon verification step is actually not.
* This is truly exceptional and shouldn't be just thrown aside.
*/
// copy IllchukLock.global.php to your config/autoload/
$locker = [
// ...
'adapter_class' => 'IllchukLock\Adapter\DbMultiple', // was Adapter\Db
// ...
]
$regexCounts = [
/**
* E.g. You can create 3 'do-stuff' locks before the lock can't be taken.
* Those not matching here are allowed the usual 1.
*/
'/^do-stuff$/' => 3
];
// in controller
$locker = $this->getServiceLocator()->get('IllchukLock');
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // FALSE
// ...
// A DAY LATER
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker = $this->getServiceLocator()->get('IllchukLock');
$handle = $locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // YES
$locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // FALSE
if ($whoopsBackingOut) {
$locker->clearLock($handle);
}
$locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // YES
// copy illchuklock.global.php to your config/autoload/
$locker = [
// ...
'adapter_class' => 'IllchukLock\Adapter\Apc', // was Adapter\Db
// ...
]
// from service manager
$locker = $container->get('IllchukLock');
// alternatively, a shortcut factory that doesn't
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.