-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Mutex "m4z3p4" | ||
|
||
![](https://i.ibb.co/6Wd3SKj/depositphotos-7524421-stock-illustration-saber-vector.jpg) | ||
|
||
- This library will help you use mutex more effectively. | ||
- Different mutex for different components are presented. | ||
- In addition, you can add your own lockers and use within the library. | ||
|
||
## How to use | ||
|
||
**First example** | ||
```php | ||
$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', 'toor'); | ||
|
||
$factory = new \Foxtech\Competitor($pdo); | ||
$factory->getMutex('mutex_name')->acquire(); | ||
|
||
// some code | ||
|
||
$factory->getMutex('mutex_name')->release(); | ||
``` | ||
|
||
**Second example** | ||
```php | ||
$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', 'toor'); | ||
|
||
$factory = new \Foxtech\Competitor(); | ||
$factory->setHandler($pdo); | ||
|
||
$factory->getMutex('mutex_name')->acquire(); | ||
|
||
// some code | ||
|
||
$factory->getMutex('mutex_name')->release(); | ||
``` | ||
------------ | ||
You can also write your own mutex to a custom handler and use within our library. (**Important**: Your mutex must implement our [interface](https://github.com/foxtech6/mutex-locker/blob/master/src/foxtech/MutexInterface.php)) | ||
|
||
**Example** | ||
```php | ||
$factory = new \Foxtech\Competitor(); | ||
$factory->push(CustomHandler::class, YourMutex::class); | ||
$factory->setHandler($customHandlerObject); | ||
|
||
$factory->getMutex('mutex_name')->acquire(); | ||
|
||
// some code | ||
|
||
$factory->getMutex('mutex_name')->release(); | ||
``` | ||
|
||
|