Laravel integration for symfony/lock.
composer require simple-as-fuck/laravel-lock
Add into your .env_example and configure your environment on server.
LOCK_STORE=semaphore
If any PHP platform requirements in composer.json ends with security support, consider package version as unsupported except last version.
Supported symfony lock store are only with native blocking lock, because it is fucking effective.
-
semaphore
SemaphoreStore recommended for simple production without application server replication (lock are stored in local ram) -
flock
FlockStore recommended for local development, (lock are stored in local filesystem, so it should work everywhere) -
pgsql
PostgreSqlStore recommended for big production with application server replication (lock are stored remotely by postgres database), you can use special database for locks using setting laravel database connection nameLOCK_PGSQL_STORE_CONNECTION=some_postgers_connection_name
, by default is used default database connection
/** @var \SimpleAsFuck\LaravelLock\Service\LockManager $lockManager */
$lockManager = app()->make(\SimpleAsFuck\LaravelLock\Service\LockManager::class);
$lock = $lockManager->acquire('some_lock_key');
try {
//happy run some critical code synchronously
} finally {
$lock->release();
}