2017 © Pedro PelĂĄez
 

library laravel-padlock

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

image

desmart/laravel-padlock

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  • Monday, April 10, 2017
  • by DeSmart
  • Repository
  • 5 Watchers
  • 0 Stars
  • 799 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Padlock Script Locker for Laravel framework

Build Status, (*1)

This package allows for easily temporarily locking your scripts execution., (*2)

It might come in handy in cases such as CRON jobs that connect with unreliable APIS, where you're not 100% sure if your script won't fail at some point., (*3)

Requirements

This package requires: * PHP >= 7.0.0 * Laravel 5.3 || 5.4, (*4)

Installation

  1. $ composer require desmart/laravel-padlock
  2. Add DeSmart\Padlock\ServiceProvider to your config/app.php:
        /*
         * Package Service Providers...
         */
        DeSmart\Padlock\ServiceProvider::class,
  1. $ php artisan vendor:publish --provider="DeSmart\Padlock\ServiceProvider"
  2. Configure in config/padlock.php - choose between Database and Filesystem driver

Example usage

This package's purpose is to protect your script from being run on multiple threads., (*5)

It is useful for long-time backend jobs such as handling queries, or harvesting data from external APIs., (*6)

class FooCommand extends \Illuminate\Console\Command
{
    protected $signature = 'foo:bar';

    protected $description = 'Foo command utilizing Padlock';

    /** @var PadlockHandler */
    private $padlockHandler;

    const PADLOCK_SCRIPT = 'FooCommand';

    /** 30 seconds padlock time to live - after that your padlock will be unlocked */
    const PADLOCK_TTL = 30;

    /**
     * FooCommand constructor.
     * @param \DeSmart\Padlock\PadlockHandler $padlockHandler
     */
    public function __construct(\DeSmart\Padlock\PadlockHandler $padlockHandler)
    {
        parent::__construct();

        $this->padlockHandler = $padlockHandler;
    }

    public function handle()
    {
        if (true === $this->padlockHandler->isLocked(self::PADLOCK_SCRIPT, self::PADLOCK_TTL)) {
            echo "Padlock exists, script locked." . PHP_EOL;

            return;
        }

        $this->padlockHandler->lock(self::PADLOCK_SCRIPT);

        // do your stuff

        $this->padlockHandler->unlock(self::PADLOCK_SCRIPT);
    }
}

The Versions

10/04 2017

dev-master

9999999-dev

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

10/04 2017

1.2.2

1.2.2.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

10/04 2017

1.2.1

1.2.1.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

05/04 2017

1.2.0

1.2.0.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

13/03 2017

1.1.0

1.1.0.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

17/02 2017

1.0.1

1.0.1.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman

14/02 2017

1.0.0

1.0.0.0

Script locking mechanism for Laravel. Enables blocking scripts execution for given period, for example to avoid cron jobs overlapping

  Sources   Download

MIT

The Requires

 

The Development Requires

by MichaƂ Uberman