phlib/mutex 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

phlib/mutex

最新稳定版本:3.0.1

Composer 安装命令:

composer require phlib/mutex

包简介

PHP mutex handling in different ways

关键字:

README 文档

README

Code Checks Codecov Latest Stable Version Total Downloads Licence

PHP mutex handling in different ways

Install

Via Composer

$ composer require phlib/mutex

Usage

MySQL

$adapter = new \Phlib\Db\Adapter([
    'host' => '127.0.0.1',
    'username' => 'my-user',
    'password' => 'my-pass'
]); 
$mutex = new \Phlib\Mutex\MySQL('my-lock', $adapter);
if ($mutex->lock()) {
    // Do some data manipulation while locked
    $mutex->unlock();
}

Helpers

Get-Or-Create provides a simple way to attempt retrieval of a value, or create it using a mutex if it doesn't already exist

$getClosure = function() {
    // attempt to get a value, eg. from DB, cache, etc.
    if (!$value) {
        throw new \Phlib\Mutex\NotFoundException();
    }
    return $value;
};

$createClosure = function() {
    // attempt to create a value and write eg. to DB, cache, etc.
    return $value;
};

$value = \Phlib\Mutex\Helper::getOrCreate($mutex, $getClosure, $createClosure);

License

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2015-06-25