Brokers for ZeroMQ from TA:map project used for distributed parsing system.
sudo apt-get update -qq
sudo apt-get install -y libzmq3-dev
git clone https://github.com/mkoppanen/php-zmq.git
sh -c "cd php-zmq && phpize && ./configure && make --silent && sudo make install"
echo "extension=zmq.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
composer require limitium/zmq
phpunit
Can be used in single process, several process on single machine or on several machines.
$logger = new ZLogger('my_service_1', 'tcp://127.0.0.1:5555');
$logger->info("core is stable");
$logger->emergency("we're all going to die!");
(new Concentrator('tcp://127.0.0.1:5555'))
->setReceiver(function ($logMsg) {
$serviceName = $logMsg[0];
$time = $logMsg[1];
$logLevel = $logMsg[2];
$logMsg = $logMsg[3];
})
->listen();
With workers management (checks workers statuses, checks workers heartbeats etc)
(new Ventilator('tcp://127.0.0.1:5555'))
->setGenerator(function () {
sleep(1);
return rand();
})
->setResponder(function ($msg) {
echo $msg;
})
->listen();
(new Worker('tcp://127.0.0.1:5555'))
->setExecutor(function ($msg) {
return $msg + $msg;
})
->work();
$pub = new Publisher('tcp://127.0.0.1:5555');
$pub->send('azaza');
(new Subscriber('tcp://127.0.0.1:5555'))
->setListener(function ($msg){
echo $msg;
})
->listen();