react / zmq
ZeroMQ bindings for React.
Installs: 1 367 545
Dependents: 43
Suggesters: 8
Security: 0
Stars: 248
Watchers: 20
Forks: 49
Open Issues: 2
Requires
- php: >=5.4.0
- ext-zmq: *
- evenement/evenement: ^3.0 || ^2.0
- react/event-loop: ^1.0 || ^0.5 || ^0.4
Requires (Dev)
- ext-pcntl: *
- phpunit/phpunit: ~4.8.35 || ~5.7 || ~6.4
README
ZeroMQ bindings for React.
Install
The recommended way to install react/zmq is through composer.
composer require react/zmq
Example
And don't forget to autoload:
<?php require 'vendor/autoload.php';
Here is an example of a push socket:
<?php $loop = React\EventLoop\Factory::create(); $context = new React\ZMQ\Context($loop); $push = $context->getSocket(ZMQ::SOCKET_PUSH); $push->connect('tcp://127.0.0.1:5555'); $i = 0; $loop->addPeriodicTimer(1, function () use (&$i, $push) { $i++; echo "sending $i\n"; $push->send($i); }); $loop->run();
And the pull socket that goes with it:
<?php $loop = React\EventLoop\Factory::create(); $context = new React\ZMQ\Context($loop); $pull = $context->getSocket(ZMQ::SOCKET_PULL); $pull->bind('tcp://127.0.0.1:5555'); $pull->on('error', function ($e) { var_dump($e->getMessage()); }); $pull->on('message', function ($msg) { echo "Received: $msg\n"; }); $loop->run();
Todo
- Integration tests
- Buffer limiting
- Do not push messages if no listener
Tests
To run the test suite, you need PHPUnit.
$ phpunit
License
MIT, see LICENSE.