Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leocavalcante/swoole-mutex
🚦 Mutual exclusion abstractions for PHP's Swoole concurrency run-time.
https://github.com/leocavalcante/swoole-mutex
concurrency mutex php swoole
Last synced: about 2 months ago
JSON representation
🚦 Mutual exclusion abstractions for PHP's Swoole concurrency run-time.
- Host: GitHub
- URL: https://github.com/leocavalcante/swoole-mutex
- Owner: leocavalcante
- License: mit
- Created: 2020-04-11T15:16:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-11T20:05:27.000Z (over 4 years ago)
- Last Synced: 2024-10-03T10:49:36.664Z (2 months ago)
- Topics: concurrency, mutex, php, swoole
- Language: PHP
- Homepage:
- Size: 31.3 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swoole - leocavalcante/swoole-mutex - Mutual exclusion abstractions for PHP's Swoole concurrency run-time. (Miscellaneous)
README
# Mutex
[![Actions Status](https://github.com/leocavalcante/swoole-mutex/workflows/CI/badge.svg)](https://github.com/leocavalcante/swoole-mutex/actions)
🚦 [Mutual exclusion](https://en.wikipedia.org/wiki/Mutual_exclusion) abstractions for PHP's [Swoole](https://www.swoole.co.uk/) concurrency run-time.
> With great power comes great responsibility — Uncle Ben (I guess)
[Swoole](https://www.swoole.co.uk/) awesomeness enables concurrency across multiple processes and cores, but sharing state/memory between them isn't a straightforward achievement. [`Swoole\Table`](https://www.swoole.co.uk/docs/modules/swoole-table) comes to help, but maybe we could have an even better API for that task.
**This package is a [Facade](https://en.wikipedia.org/wiki/Facade_pattern) for [`Swoole\Table`](https://www.swoole.co.uk/docs/modules/swoole-table) providing common APIs for mutual exclusion patterns.**
_We all hail [**Edsger W. Dijkstra**](https://en.wikipedia.org/wiki/Edsger_W._Dijkstra) (and [Swoole team](https://github.com/orgs/swoole/people) for their amazing work)._
## Install
```bash
composer require leocavalcante/swoole-mutex
```## Example
Counting HTTP requests across >1 workers.
```php
use Mutex\Atomic\Integer;
use Swoole\Http\{Request, Response, Server};$counter = new Integer();
$server = new Server('127.0.0.1', 8000);$server->on('request', function (Request $req, Response $res) use ($counter): void {
if ($req->server['request_uri'] !== '/favicon.ico') {
$counter->inc();
}$res->end('You are number: ' . $counter->value());
});$server->set(['worker_num' => 4]);
$server->start();
```---
© 2k2O