Giter Site home page Giter Site logo

laravel-lock's Introduction

Laravel Lock

Latest Version on Packagist Build Status

##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 [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-lock's People

Contributors

hollyit avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-lock's Issues

laravel 8 support?

Hi,
i really like this integration for laravel, but i work on project use newest laravel version.
Can you update library compatible with laravel 8? Or can i help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.