hollyit / laravel-lock
A Laravel wrapper for the Symfony Lock component to provide semaphore style locks on long running processes.
Installs: 1 561
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.1.3
- ext-pdo: *
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0.0
- symfony/lock: ^4.3
Requires (Dev)
- orchestra/testbench: 3.8.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-10-29 06:11:36 UTC
README
##Description
A simple Laravel wrapper for the Symfony lock component to provide semaphore locking.
Why?
When you have routines that take a longer time than usual to run, you may not want other processes attempting to run it. To prevent this you can acquire what is referred to as a lock or semaphore. This prevents problems of contention.
Installation
You can install the package via composer:
composer require hollyit/laravel-lock
Usage
$lock = LaravelLock::make('test-lock') if ($lock->acquire()) { // Perform my long running task $lock->release(); } else { // Something is already running on this process so let's not do anything. }
Currently supported drivers
Drivers can be configured in config/lock.php. View that file for additional details. To publish the configuration
php artisan vendor:publish --provider="Hollyit\LaravelLock\LaravelLockServiceProvider" --tag="config"
File Drive:
(This is a wrapper of the Symfony FlockStore)
No additional setup required. By default this will use the system's temporary directory. You may override this in config or environment. Please see config/lock.php for details.
With the exception of Database, drivers are very simple wrappers. If you would like to add additional drivers, please consider a PR.
Database driver:
(This is a modification of the PdoStore, modified to use Laravel's database layer)
This will use your default database connection. Before using this driver you must publish and migrate your database.
php artisan vendor:publish --provider="Hollyit\LaravelLock\LaravelLockServiceProvider" --tag="migraions"
If you wish to use a custom table name, then please modify your config/lock.php file prior to migrating.
Redis:
Redis isn't currently supported, but it will in a future release.
Custom drivers:
Other stores from the Symfony/lock package aren't currently supported. Migrating them over should be rather simple if you would like to (and please submit a PR).
You may also define custom drivers outside of what the original symfony/lock package offers. Under your config/lock.php configuration file, simple define a 'class' property to point to the class of the new driver. Drivers must implement the \Hollyit\LaravelLock\Contracts\LockDriver contract.
Additional details
For additional details and features, please refer to the Symfony Lock documentation.
Testing
NOTE: Testing is extremely limited at this time given the need for this package on a client project. If you are willing to expand on test coverage, please do so and submit a PR.
composer test
Contributing
This package was quickly developed due to the need of a current client project. If you would like to add more drivers, features or tests, then your help will be greatly welcomed.
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email jamie@hollyit.net instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.