hisorange / posix-rpc
Easy to use RPC library written in PHP for messaging through Posix queues.
Installs: 4 220
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- evenement/evenement: ^3.0 || ^2.0
- monolog/monolog: ^2.0
- psr/log: ^1.1
- rybakit/msgpack: ^0.7.0
Requires (Dev)
- kahlan/kahlan: ^4.7
- phpstan/phpstan: ^0.12.11
- satooshi/php-coveralls: ^2.2
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-10-24 07:40:30 UTC
README
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
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:
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.
$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
$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.
// Would be funny, right? $worker->respond->calculator->sum('array_sum'); // Other machine. $six = $main->request->calculator->sum([1, 2, 3]);