https://github.com/hisorange/posix-rpc
Posix RPC for PHP by hisorange! https://hisorange.me/
https://github.com/hisorange/posix-rpc
ipc messaging php posix rpc
Last synced: 2 months ago
JSON representation
Posix RPC for PHP by hisorange! https://hisorange.me/
- Host: GitHub
- URL: https://github.com/hisorange/posix-rpc
- Owner: hisorange
- License: mit
- Created: 2020-02-23T21:26:23.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2020-02-23T21:44:47.000Z (over 5 years ago)
- Last Synced: 2025-02-05T06:51:15.093Z (4 months ago)
- Topics: ipc, messaging, php, posix, rpc
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
## PosixRPC for PHP by _[hisorange](https://hisorange.me)_
[](https://packagist.org/packages/hisorange/posix-rpc)
[](https://travis-ci.org/hisorange/posix-rpc)
[](https://coveralls.io/github/hisorange/posix-rpc)
[](https://packagist.org/packages/hisorange/posix-rpc)
[](https://packagist.org/packages/hisorange/posix-rpc)Easy to use library to handle the **IPC** (Inter Process Communication) for You!
It provides a messaging interface for publish / subscribe pattern, and also supports safe **RPC** (Remote Procedure Calls).
That is not all! With an intuitive syntax You can call handlers **synchronously** or **asynchronously** with a non-blocking transport layer.But wait, isn't Posix queues are small and slow?!
Nope! This library can push gigabyte sized messages through the queue, and can easily reach 30k messages per second ^.^Let's get started!
### How to install
---
```sh
composer require hisorange/posix-rpc
```Yep, it's ready to be used by You! ^.^
### How to use:
---
No need for big setup, just initialize a node with a unique name:
```php
use hisorange\PosixRPC\Node;
use hisorange\PosixRPC\Contract\IMessage;$main = new Node('main');
$worker = new Node('worker');// Do the "hard" job here ^.^
$worker->respond->sum(function(IMessage $message) {
return array_sum($message->getPayload());
});// Yep, You can scale your app this easily!
$twelve = $main->request->sum([10, 2]);// Also, You can simply publish messages which does not expect an answear!
$main->publish('log.error', 'Database connection refused!');// And listen on them in Your lazy process
$worker->subscribe('log.error', function(IMessage $message) {
take_action($message->getPayload());
});
```### Async / Sync calls
---
By default every message sent async, and You could pool the transport for messages.
But if You wana sequence a logic and Your process can block execution while waiting for a message,
then You can use the await call, this will pool the transport until the response is arrived.```php
$worker->respond('sum', function($request) {
return my_array_sum($request);
});// Will pool the transport until the response is arrived.
$response = $main->request('sum', [10, 2]);
```Async syntax
```php
$worker->respond('sum', 'array_sum');$main->request('sum', [10, 2], function($response) {
assert($response, 12);
});// Call the pool, when Your process is free to receive messages.
$main->tick();
```### Fluent calls
To make the usage more programer friendly, the package supports fluent syntax.
```php
// Would be funny, right?
$worker->respond->calculator->sum('array_sum');// Other machine.
$six = $main->request->calculator->sum([1, 2, 3]);
```