PHP code example of sacred / prevent-race-condition
1. Go to this page and download the library: Download sacred/prevent-race-condition 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/ */
sacred / prevent-race-condition example snippets
use PreventRaceCondition\RaceConditionFactory;
// $somePSR16Cache is PSR16 any cache instance
$raceCondition = RaceConditionFactory::fromCacheItemPool($somePSR16Cache);
// or
// $somePSR6Cache is PSR6 any cache instance
$raceCondition = RaceConditionFactory::fromSimpleCache($somePSR6Cache);
while($raceCondition->isBusy('lock-name')) {
// wait or do something else
}
$raceCondition->lock('lock-name');
// do something
$raceCondition->release('lock-name');