定制 desmart/laravel-padlock 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

desmart/laravel-padlock

Composer 安装命令:

composer require desmart/laravel-padlock

包简介

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

README 文档

README

Build Status

This package allows for easily temporarily locking your scripts execution.

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.

Requirements

This package requires:

  • PHP >= 7.0.0
  • Laravel 5.3 || 5.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.

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

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);
    }
}

统计信息

  • 总下载量: 814
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固