2017 © Pedro Peláez
 

library mutex

PHP mutex handling in different ways

image

phlib/mutex

PHP mutex handling in different ways

  • Wednesday, February 28, 2018
  • by letssurf
  • Repository
  • 1 Watchers
  • 1 Stars
  • 109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

phlib/mutex

Code Checks Codecov Latest Stable Version Total Downloads Licence, (*1)

PHP mutex handling in different ways, (*2)

Install

Via Composer, (*3)

``` bash $ composer require phlib/mutex, (*4)


## Usage ### MySQL ```php $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, (*5)

$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., (*6)

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., (*7)

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/., (*8)

The Versions

28/02 2018

dev-master

9999999-dev https://github.com/phlib/mutex

PHP mutex handling in different ways

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster

mutex phlib

28/02 2018

2.0.0

2.0.0.0 https://github.com/phlib/mutex

PHP mutex handling in different ways

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster

mutex phlib

28/02 2018

dev-feature/phlib-config-2

dev-feature/phlib-config-2 https://github.com/phlib/mutex

PHP mutex handling in different ways

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster

mutex phlib

25/06 2015

1.0.1

1.0.1.0 https://github.com/phlib/mutex

PHP mutex handling in different ways

  Sources   Download

The Requires

 

The Development Requires

by James Dempster

mutex phlib

23/06 2015

1.0.0

1.0.0.0 https://github.com/phlib/mutex

PHP mutex handling in different ways

  Sources   Download

The Requires

 

The Development Requires

by James Dempster

mutex phlib