rsocket / rsocket-php
RSocket PHP SDK based on ReactPHP and RxPHP
0.2.0
2022-01-28 00:00 UTC
Requires
- php: >=7.4
- ext-json: *
- cboden/ratchet: ^0.4
- ratchet/pawl: ^0.3
- react/event-loop: v1.2.0
- react/socket: v1.11.0
- reactivex/rxphp: 2.0.10
Requires (Dev)
- phpunit/phpunit: 9.*
This package is not auto-updated.
Last update: 2025-03-23 16:33:12 UTC
README
RSocket PHP SDK based on ReactPHP and RxPHP.
Requirements
- PHP 7.4+
Examples
RSocket Client
Scheduler::setDefaultFactory(function () { return new Scheduler\EventLoopScheduler(Loop::get()); }); $rsocketPromise = RSocketConnector::create()->connect("tcp://127.0.0.1:42252"); $rsocketPromise->then(function (RSocket $rsocket) { $observablePayload = $rsocket->requestResponse(Payload::fromText("text/plain", "Ping")); $observablePayload->subscribe( function (Payload $x) { echo 'Result: ' . $x->getDataUtf8(); } ); });
RSocket Server
Scheduler::setDefaultFactory(function () { return new Scheduler\EventLoopScheduler(Loop::get()); }); $listenUri = "tcp://127.0.0.1:42252"; $socketAcceptor = CallableSocketAcceptor::handle(function ($setupPayload, $sendingRSocket) { return AbstractRSocket::requestResponseHandler(function ($payload) { return Observable::of(Payload::fromText("metadata", "PONG")); }); }); $server = RSocketServer::create($socketAcceptor)->bind($listenUri); print("RSocket Server started on ${listenUri}");
RSocket Service stub and routing
Please check https://github.com/rsocket/rsocket-php/tree/master/tests/route
RSocket
- Operations
- REQUEST_FNF
- REQUEST_RESPONSE
- REQUEST_STREAM
- REQUEST_CHANNEL
- METADATA_PUSH
- More Operations
- Error
- Cancel
- Keepalive
- QoS
- RequestN
- Lease
- Transport
- TCP
- Websocket
- High Level APIs
- Client
- Server
- Misc
- RxPHP
References
- RSocket: https://rsocket.io
- ReactPHP: https://github.com/reactphp/reactphp
- ReactPHP Projects: https://github.com/reactphp/reactphp/wiki/Users
- RxPHP: https://github.com/ReactiveX/RxPHP
- New .phpstorm.meta.php features: https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/
- PHP Reactive Programming: https://www.packtpub.com/web-development/php-reactive-programming
- Ratchet: Asynchronous WebSocket server https://github.com/ratchetphp/Ratchet
- Pawl: asynchronous WebSocket client https://github.com/ratchetphp/Pawl
- PHP 8: Attributes: https://stitcher.io/blog/attributes-in-php-8