Download the PHP package m-rubin-itmegastar-com/lock without Composer

On this page you can find all versions of the php package m-rubin-itmegastar-com/lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lock

Requirements | Installation | Usage | License and authors | Donations

php-lock/lock

Latest Stable Version Total Downloads Build Status License

This library helps executing critical code in concurrent situations.

php-lock/lock follows semantic versioning. Read more on semver.org.


Requirements


Installation

Composer

To use this library through composer, run the following terminal command inside your repository's root folder.

Usage

The package is in the namespace m_rubin_itmegastar_com\lock.

Mutex

The malkusch\lock\mutex\Mutex class is an abstract class and provides the base API for this library.

Mutex::synchronized()

malkusch\lock\mutex\Mutex::synchronized() executes code exclusively. This method guarantees that the code is only executed by one process at once. Other processes have to wait until the mutex is available. The critical code may throw an exception, which would release the lock as well.

This method returns whatever is returned to the given callable. The return value is not checked, thus it is up to the user to decide if for example the return value false or null should be seen as a failed action.

Example:

Mutex::check()

malkusch\lock\mutex\Mutex::check() sets a callable, which will be executed when malkusch\lock\util\DoubleCheckedLocking::then() is called, and performs a double-checked locking pattern, where it's return value decides if the lock needs to be acquired and the synchronized code to be executed.

See https://en.wikipedia.org/wiki/Double-checked_locking for a more detailed explanation of that feature.

If the check's callable returns false, no lock will be acquired and the synchronized code will not be executed. In this case the malkusch\lock\util\DoubleCheckedLocking::then() method, will also return false to indicate that the check did not pass either before or after acquiring the lock.

In the case where the check's callable returns a value other than false, the malkusch\lock\util\DoubleCheckedLocking::then() method, will try to acquire the lock and on success will perform the check again. Only when the check returns something other than false a second time, the synchronized code callable, which has been passed to then() will be executed. In this case the return value of then() will be what ever the given callable returns and thus up to the user to return false or null to indicate a failed action as this return value will not be checked by the library.

Example:

Extracting code result after lock release exception

Mutex implementations based on malkush\lock\mutex\LockMutex will throw malkusch\lock\exception\LockReleaseException in case of lock release problem, but the synchronized code block will be already executed at this point. In order to read the code result (or an exception thrown there), LockReleaseException provides methods to extract it.

Example:

Implementations

Because the malkusch\lock\mutex\Mutex class is an abstract class, you can choose from one of the provided implementations or create/extend your own implementation.

CASMutex

The CASMutex has to be used with a Compare-and-swap operation. This mutex is lock free. It will repeat executing the code until the CAS operation was successful. The code should therefore notify the mutex by calling malkusch\lock\mutex\CASMutex::notify().

As the mutex keeps executing the critical code, it must not have any side effects as long as the CAS operation was not successful.

Example:

FlockMutex

The FlockMutex is a lock implementation based on flock().

Example:

Timeouts are supported as an optional second argument. This uses the ext-pcntl extension if possible or busy waiting if not.

MemcachedMutex

The MemcachedMutex is a spinlock implementation which uses the Memcached API.

Example:

PHPRedisMutex

The PHPRedisMutex is the distributed lock implementation of RedLock which uses the phpredis extension.

This implementation requires at least phpredis-2.2.4.

If used with a cluster of Redis servers, acquiring and releasing locks will continue to function as long as a majority of the servers still works.

Example:

PredisMutex

The PredisMutex is the distributed lock implementation of RedLock which uses the Predis API.

Example:

SemaphoreMutex

The SemaphoreMutex is a lock implementation based on Semaphore.

Example:

TransactionalMutex

The TransactionalMutex delegates the serialization to the DBS. The exclusive code is executed within a transaction. It's up to you to set the correct transaction isolation level. However if the transaction fails (i.e. a PDOException was thrown), the code will be executed again in a new transaction. Therefore the code must not have any side effects besides SQL statements. Also the isolation level should be conserved for the repeated transaction. If the code throws an exception, the transaction is rolled back and not replayed again.

Example:

MySQLMutex

The MySQLMutex uses MySQL's GET_LOCK function.

It supports time outs. If the connection to the database server is lost or interrupted, the lock is automatically released.

Note that before MySQL 5.7.5 you cannot use nested locks, any new lock will silently release already held locks. You should probably refrain from using this mutex on MySQL versions < 5.7.5.

PgAdvisoryLockMutex

The PgAdvisoryLockMutex uses PostgreSQL's advisory locking functions.

Named locks are offered. PostgreSQL locking functions require integers but the conversion is handled automatically.

No time outs are supported. If the connection to the database server is lost or interrupted, the lock is automatically released.

License and authors

This project is free and under the WTFPL. Responsible for this project is Willem Stuursma-Ruwen [email protected].

Donations

If you like this project and feel generous donate a few Bitcoins here: 1P5FAZ4QhXCuwYPnLZdk3PJsqePbu1UDDA


All versions of lock with dependencies

PHP Build Version
Package Version
Requires php Version ~7.0
psr/log Version ^1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package m-rubin-itmegastar-com/lock contains the following files

Loading the files please wait ....