/**
  * Sets up loop and server manually to allow periodic timer calls.
  */
 private function setupServer()
 {
     $this->setupApp();
     /** @var $loop \React\EventLoop\LoopInterface */
     $this->loop = \React\EventLoop\Factory::create();
     // Enable ZMQ Listener.
     // Requires , "react/zmq" package.
     $zmq = $this->getContainer()->getParameter('jdare_clank.zmq_configuration');
     if ($zmq['enabled']) {
         if (!class_exists('\\ZMQContext')) {
             throw new \Exception("Could not find ZMQContext, did you install the zmq bindings for PHP?");
         }
         // Listen for the web server to make a ZeroMQ push after an ajax request
         $context = new \React\ZMQ\Context($this->loop);
         $pull = $context->getSocket(\ZMQ::SOCKET_PULL);
         $bind = "tcp://127.0.0.1:{$zmq['port']}";
         echo "\nListening to ZMQ messages on {$bind}\n";
         $pull->bind($bind);
         // Binding to 127.0.0.1 means the only client that can connect is itself
         $pull->on('message', array($this->getContainer()->get("jdare_clank.clank_app"), 'onZMQMessage'));
     }
     $this->socket = new \React\Socket\Server($this->loop);
     if ($this->host) {
         $this->socket->listen($this->port, $this->host);
     } else {
         $this->socket->listen($this->port);
     }
     $this->setupPeriodicServices();
     $this->server = new \Ratchet\Server\IoServer($this->app, $this->socket, $this->loop);
 }
Esempio n. 2
0
 public function __construct(LoopInterface $loop)
 {
     $context = new \React\ZMQ\Context($loop);
     $pusher = new Pusher();
     $workers = $context->getSocket(\ZMQ::SOCKET_PUSH);
     $workers->bind("tcp://127.0.0.1:5557");
     // Listen for work from the web
     $receiver = $context->getSocket(\ZMQ::SOCKET_PULL);
     $receiver->bind("tcp://127.0.0.1:5555");
     $receiver->on('message', function ($msg) use($workers) {
         // Create
         echo "Received: " . $msg . "\n";
         $workers->send($msg);
     });
     $control = $context->getSocket(\ZMQ::SOCKET_PULL);
     $control->bind('tcp://127.0.0.1:5510');
     $control->on('message', function ($msg) use($pusher) {
         echo "CONTROL MESSAGE\n";
         $arr = json_decode($msg, true);
         $slug = $arr['slug'];
         $req = $arr['req'];
         $pusher->send($slug, $arr['req']);
     });
     $listener = $context->getSocket(\ZMQ::SOCKET_PULL);
     $listener->bind('tcp://127.0.0.1:5559');
     $listener->on('message', function ($msg) use($pusher) {
         echo " + - - - - - - - - - + \n";
         echo "       RESULTS         \n";
         print_r($msg);
         $message = json_decode($msg, true);
         if ($message['command'] == 'client.gotRequest') {
             $pusher->onClientGotRequest($message['slug']);
         } else {
             if ($message['command'] == 'client.gotPayment') {
                 $pusher->onClientGotPayment($message['slug']);
             } else {
                 if ($message['command'] == 'tx.complete') {
                     try {
                         $request = Request::find(['slug' => $message['slug']]);
                         $transaction = TransactionFactory::fromHex($message['tx']);
                         Transaction::create(['transaction' => $message['tx'], 'request_id' => $request->id, 'txid' => $transaction->getTransactionId()]);
                         $pusher->onCompleteTx($message['slug'], $message['tx']);
                     } catch (\Exception $e) {
                         return;
                     }
                 } else {
                     if ($message['command'] == 'tx.partial') {
                         $pusher->onCompleteTx($message['slug'], $message['tx']);
                     }
                 }
             }
         }
         echo "\n + - - - - - - - - - + \n\n";
     });
     // Set up our WebSocket server for clients wanting real-time updates
     $webSock = new \React\Socket\Server($loop);
     $webSock->listen(8080, '0.0.0.0');
     // Binding to 0.0.0.0 means remotes can connect
     $webServer = new \Ratchet\Server\IoServer(new \Ratchet\Http\HttpServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($pusher))), $webSock);
 }
function pull_routine()
{
    $loop = React\EventLoop\Factory::create();
    $context = new React\ZMQ\Context($loop);
    $socket = $context->getSocket(ZMQ::SOCKET_PULL);
    $socket->bind('ipc://test.ipc');
    $socket->on('message', function () {
        echo "-";
    });
    $loop->run();
}
Esempio n. 4
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loop = \React\EventLoop\Factory::create();
     $context = new \React\ZMQ\Context($loop);
     $push = $context->getSocket(\ZMQ::SOCKET_REQ);
     $push->connect('tcp://127.0.0.1:5560');
     $push->on('message', function ($message = '') use($loop) {
         echo $message . PHP_EOL;
         $loop->stop();
     });
     $push->send(json_encode(['cmd' => 'stop']));
     $loop->run();
 }
Esempio n. 5
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loop = \React\EventLoop\Factory::create();
     $context = new \React\ZMQ\Context($loop);
     $push = $context->getSocket(\ZMQ::SOCKET_REQ);
     $push->connect('tcp://127.0.0.1:5560');
     $push->on('message', function ($message = '') use($loop) {
         if ($message == 'shutdown') {
             echo "Shutdown successfully\n";
         }
         $loop->stop();
     });
     $push->send('shutdown');
     $loop->run();
 }
function push_routine()
{
    $loop = React\EventLoop\Factory::create();
    $context = new React\ZMQ\Context($loop);
    $socket = $context->getSocket(ZMQ::SOCKET_PUSH);
    $socket->connect('ipc://test2.ipc');
    $loop->addPeriodicTimer(1, function () use($socket) {
        for ($n = 0; $n < rand(1, 30000); $n++) {
            if (rand(0, 100) >= 50) {
                echo "s";
                $socket->send('bogus-' . $n);
            } else {
                echo "m";
                $socket->send(array("bogus{$n}-1", "bogus{$n}-2", "bogus{$n}-3"));
            }
        }
    });
    $loop->run();
}
Esempio n. 7
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //Init rena
     $app = MiraApp::getInstance();
     // Setup the react event loop and call up the pusher class
     $loop = \React\EventLoop\Factory::create();
     $pusher = new Pusher();
     $stomper = new stompSend();
     // ZeroMQ server
     $context = new \React\ZMQ\Context($loop);
     $pull = $context->getSocket(ZMQ::SOCKET_PULL);
     $pull->bind("tcp://127.0.0.1:5555");
     $pull->on("message", array($pusher, "onMessage"));
     $pull->on("message", array($stomper, "onMessage"));
     // Websocket server
     $webSock = new \React\Socket\Server($loop);
     $webSock->listen(8800, "0.0.0.0");
     $webServer = new \Ratchet\Server\IoServer(new \Ratchet\Http\HttpServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($pusher))), $webSock);
     $loop->run();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $loop = React\EventLoop\Factory::create();
     $pusher = new LowEndPing\Pusher();
     $zmq_host = Config::get('lowendping.websocket.zeromq.host', '127.0.0.1') . ':' . Config::get('lowendping.websocket.zeromq.port', 5555);
     // Listen for the web server to make a ZeroMQ push after a response
     $context = new React\ZMQ\Context($loop);
     $pull = $context->getSocket(ZMQ::SOCKET_PULL);
     $this->info('Binding ZMQ to ' . $zmq_host);
     $pull->bind('tcp://' . $zmq_host);
     // Binding to 127.0.0.1 means the only client that can connect is itself
     $pull->on('message', array($pusher, 'onServerResponse'));
     $this->info('Binding Ratchet Websocket to 0.0.0.0:' . Config::get('lowendping.websocket.port', 8080));
     // Set up our WebSocket server for clients wanting real-time updates
     $webSock = new React\Socket\Server($loop);
     $webSock->listen(Config::get('lowendping.websocket.port', 8080), '0.0.0.0');
     // Binding to 0.0.0.0 means remotes can connect
     $webServer = new Ratchet\Server\IoServer(new Ratchet\Http\HttpServer(new Ratchet\WebSocket\WsServer(new Ratchet\Wamp\WampServer($pusher))), $webSock);
     $loop->run();
 }
Esempio n. 9
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use ShortFlake\IdGenerator;
$loop = React\EventLoop\Factory::create();
$id_generator = new IdGenerator($loop);
$context = new React\ZMQ\Context($loop);
$socket = $context->getSocket(ZMQ::SOCKET_REP);
$socket->bind('tcp://127.0.0.1:1337');
$socket->on('message', function ($message) use($id_generator, $socket) {
    if ('id' == $message) {
        $id_generator->computeId()->then(function ($uuid) use($socket) {
            $socket->send($uuid);
        });
    }
});
$loop->run();
Esempio n. 10
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$pub = $context->getSocket(ZMQ::SOCKET_PUB);
$pub->bind('tcp://127.0.0.1:5555');
$i = 0;
$loop->addPeriodicTimer(1, function () use(&$i, $pub) {
    $i++;
    switch (mt_rand(1, 3)) {
        case 1:
            $subject = 'Автомобили';
            break;
        case 2:
            $subject = 'Электроника';
            break;
        case 3:
            $subject = 'Спорт';
            break;
    }
    printf('Отправил сообщение [%d] | Тема сообщения [%s]' . PHP_EOL, $i, $subject);
    $pub->send(sprintf('%s %d', $subject, $i));
});
$loop->run();
Esempio n. 11
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$receiver = $context->getSocket(ZMQ::SOCKET_PULL);
$receiver->connect('tcp://127.0.0.1:5557');
$sender = $context->getSocket(ZMQ::SOCKET_PUSH);
$sender->connect('tcp://127.0.0.1:5558');
$receiver->on('message', function ($msg) use($loop, $sender) {
    echo "Получил сообщение [{$msg}]", PHP_EOL;
    // задержка ответа 2-4 сек
    $loop->addTimer(rand(2, 4), function () use($sender, $msg) {
        // отправляем ответ клиенту
        printf("Отправил результат [%s]" . PHP_EOL, $msg);
        $sender->send(sprintf("%s", $msg));
    });
});
$loop->run();
 /**
  * Get the WampServer driver.
  *
  * @param [type] $ratchetServer [description]
  *
  * @return [type] [description]
  */
 private function startWampServer()
 {
     $loop = \React\EventLoop\Factory::create();
     $class = $this->option('class');
     $ratchetServer = new $class($this);
     $this->info(sprintf('Starting ZMQ server on: %s:%s', config('ratchet.zmq.host'), config('ratchet.zmq.port')));
     $context = new \React\ZMQ\Context($loop);
     $pull = $context->getSocket(\ZMQ::SOCKET_PULL);
     $pull->bind(sprintf('tcp://%s:%d', config('ratchet.zmq.host'), config('ratchet.zmq.port')));
     $pull->on('message', function ($message) use($ratchetServer) {
         $ratchetServer->onEntry($message);
     });
     $webSock = new \React\Socket\Server($loop);
     $webSock->listen($this->port, $this->host);
     $webServer = new \Ratchet\Server\IoServer(new \Ratchet\Http\HttpServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($ratchetServer))), $webSock);
     return $loop;
 }
Esempio n. 13
0
}
chdir(dirname($config));
$config = json_decode(file_get_contents($config));
if ($config->debug) {
    $logLevel = \Monolog\Logger::DEBUG;
} else {
    $logLevel = \Monolog\Logger::WARNING;
}
// Set up logging to file
$log = new \Monolog\Logger('xmr');
$log->pushHandler(new \Monolog\Handler\StreamHandler('log.txt', $logLevel));
$log->pushHandler(new \Monolog\Handler\StreamHandler(STDOUT, $logLevel));
$log->info(sprintf('Starting up - listening for CMS on %s.', $config->listenOn));
try {
    $loop = React\EventLoop\Factory::create();
    $context = new React\ZMQ\Context($loop);
    // Reply socket for requests from CMS
    $responder = $context->getSocket(ZMQ::SOCKET_REP);
    $responder->bind($config->listenOn);
    // Pub socket for messages to Players (subs)
    $publisher = $context->getSocket(ZMQ::SOCKET_PUB);
    foreach ($config->pubOn as $pubOn) {
        $log->info(sprintf('Bind to %s for Publish.', $pubOn));
        $publisher->bind($pubOn);
    }
    // REP
    $responder->on('error', function ($e) use($log) {
        $log->error($e->getMessage());
    });
    $responder->on('message', function ($msg) use($log, $responder, $publisher) {
        try {
Esempio n. 14
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$router = $context->getSocket(ZMQ::SOCKET_ROUTER);
$router->bind('tcp://127.0.0.1:5555');
$dealer = $context->getSocket(ZMQ::SOCKET_DEALER);
$dealer->bind('tcp://127.0.0.1:5556');
$router->on('messages', function ($msg) use($dealer) {
    printf('Получил запрос "%s". Переправил' . PHP_EOL, $msg[2]);
    $dealer->send($msg);
});
$dealer->on('messages', function ($msg) use($router) {
    printf('Получил ответ "%s". Переправил' . PHP_EOL, $msg[2]);
    $router->send($msg);
});
$loop->run();
Esempio n. 15
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$requester = $context->getSocket(ZMQ::SOCKET_REQ);
$requester->on('message', function ($reply) {
    printf('Получил ответ [%s]' . PHP_EOL, $reply);
});
$requester->connect('tcp://127.0.0.1:5555');
$i = 0;
$loop->addPeriodicTimer(1, function () use(&$i, $requester) {
    printf('Отправил запрос [%d]' . PHP_EOL, $i);
    $requester->send($i);
    $i++;
});
$loop->run();
Esempio n. 16
0
<?php

require __DIR__ . '/../vendor/autoload.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();
Esempio n. 17
0
 /**
  * @param LoopInterface $loop
  */
 public function initZmq(LoopInterface $loop)
 {
     /** @var \ZMQContext $context */
     $context = new \React\ZMQ\Context($loop);
     $this->listener = $context->getSocket(\ZMQ::SOCKET_PUSH);
     $this->listener->connect('tcp://127.0.0.1:5559');
     $this->receiver = $context->getSocket(\ZMQ::SOCKET_PULL);
     $this->receiver->connect('tcp://127.0.0.1:5557');
     $this->receiver->on('message', function ($msg) {
         $message = json_decode($msg, true);
         if (is_array($message) && isset($message['outputs']) && is_array($message['outputs'])) {
             $cumulative = array();
             foreach ($message['outputs'] as $output) {
                 $script = pack("H*", $output['script']);
                 if (!isset($cumulative[$script])) {
                     $cumulative[$script] = $output['value'];
                 } else {
                     $cumulative[$script] += $output['value'];
                 }
             }
             $message['requirements'] = $cumulative;
             $this->contracts[$message['slug']] = $message;
             echo "New contract: " . $msg . "\n";
         }
     });
 }
Esempio n. 18
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$responder = $context->getSocket(ZMQ::SOCKET_REP);
$timestamp = new ZeroReactExamples\Utilits\Timestamp();
$responder->on('message', function ($request) use($loop, $responder, $timestamp) {
    printf("Получил запрос [%s]" . PHP_EOL, $request);
    $receiveTime = $timestamp->getTime();
    // задержка ответа 2-4 сек
    $loop->addTimer(rand(2, 4), function () use($responder, $request, $receiveTime, $timestamp) {
        // отправляем ответ клиенту
        printf("Отправил ответ [%s]" . PHP_EOL, $request);
        $responder->send(sprintf("%s | Получил: %s | Ответил: %s", $request, $receiveTime, $timestamp->getTime()));
    });
});
$responder->bind('tcp://127.0.0.1:5555');
$loop->run();
Esempio n. 19
0
<?php

error_reporting(E_ERROR);
require __DIR__ . "/vendor/autoload.php";
require __DIR__ . "/event_handler.php";
$loop = React\EventLoop\Factory::create();
$evHndler = new event_handler();
$zctx = new React\ZMQ\Context($loop);
$rcvr = $zctx->getSocket(ZMQ::SOCKET_PULL);
$rcvr->bind("tcp://127.0.0.1:5555");
$rcvr->on('message', array($evHndler, 'onPush'));
$app = new Ratchet\App('gamecon-shirofuji.c9.io', 8081, '0.0.0.0', $loop);
$app->route('/game', $evHndler);
$app->run();
Esempio n. 20
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$sub = $context->getSocket(\ZMQ::SOCKET_SUB);
$sub->connect('tcp://127.0.0.1:5555');
$sub->subscribe('sub');
$sub->on('messages', function ($msg) {
    echo "Received: " . $msg[1] . " on channel: " . $msg[0] . "\n";
});
$bus = $context->getSocket(\ZMQ::SOCKET_SUB);
$bus->connect('tcp://127.0.0.1:5555');
$bus->subscribe('bus');
$bus->on('messages', function ($msg) {
    echo $msg[0] . " :lennahc no " . $msg[1] . " :devieceR\n";
});
$pub = $context->getSocket(\ZMQ::SOCKET_PUB);
$pub->bind('tcp://127.0.0.1:5555');
$i = 0;
$loop->addPeriodicTimer(1, function () use(&$i, $pub) {
    $i++;
    echo "publishing {$i}\n";
    $pub->sendmulti(array('sub', $i));
    // you get this one in the sub socket
    $pub->sendmulti(array('bus', $i));
    // you don't get this one
});
$loop->run();
Esempio n. 21
0
<?php

require "../vendor/autoload.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');
$push->send(json_encode(["command" => "new"]));
$loop->run();
Esempio n. 22
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$sub = $context->getSocket(ZMQ::SOCKET_SUB);
$sub->connect('tcp://127.0.0.1:5556');
$sub->subscribe('');
echo 'Подписался на все темы', PHP_EOL;
$sub->on('message', function ($msg) {
    printf('Получил сообщение [%s]' . PHP_EOL, $msg);
});
$loop->run();
Esempio n. 23
0
<?php

require 'vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$context = new React\ZMQ\Context($loop);
$dealer = $context->getSocket(ZMQ::SOCKET_DEALER);
$dealer->bind('tcp://127.0.0.1:4444');
$conns = new ArrayObject();
$dealer->on('message', function ($msg) use($conns) {
    list($hash, $blank, $data) = $msg;
    if (!isset($conns[$hash])) {
        return;
    }
    $response = $conns[$hash];
    $response->writeHead();
    $response->end($data);
});
$http->on('request', function ($request, $response) use($dealer, $conns) {
    $hash = spl_object_hash($request);
    $conns[$hash] = $response;
    $request->on('end', function () use($conns, $hash) {
        unset($conns[$hash]);
    });
    $dealer->send(array($hash, '', $request->getPath()));
});
$socket->listen(8080);
$loop->run();
Esempio n. 24
0
$stdin_connection = $connection . $stdin_port;
$control_connection = $connection . $control_port;
$hb_connection = $connection . $hb_port;
$shell_connection = $connection . $shell_port;
$iopub_connection = $connection . $iopub_port;
$session_id = Uuid::uuid4();
$kernel->setEngineId(Uuid::uuid4());
if (!isset(Kernel::getSignatureSchemes()[$kernel->getSignatureScheme()])) {
    trigger_error("invalid signature scheme:{$kernel->getSignatureScheme()}\n");
    exit;
}
// Open all needed sockets.
$context = new ZMQContext();
$loop = React\EventLoop\Factory::create();
/** @var $context \ZMQContext */
$context = new React\ZMQ\Context($loop);
/** @var $hb_socket \ZMQSocket */
$hb_socket = $context->getSocket(ZMQ::SOCKET_REP);
$hb_socket->bind($hb_connection);
/** @var $iopub_socket \ZMQSocket */
$iopub_socket = $context->getSocket(ZMQ::SOCKET_PUB);
$iopub_socket->bind($iopub_connection);
/** @var $control_socket \ZMQSocket */
$control_socket = $context->getSocket(ZMQ::SOCKET_ROUTER);
$control_socket->bind($control_connection);
/** @var $stdin_socket \ZMQSocket */
$stdin_socket = $context->getSocket(ZMQ::SOCKET_ROUTER);
$stdin_socket->bind($stdin_connection);
/** @var $shell_socket \ZMQSocket */
$shell_socket = $context->getSocket(ZMQ::SOCKET_ROUTER);
$shell_socket->bind($shell_connection);
Esempio n. 25
0
 /**
  * Run WebSocket Server
  *
  * Usage (from command line):
  * 
  * php oil r ratchet:wamp <class_name>
  * 
  * Note:
  * http://socketo.me/docs/push
  * http://socketo.me/docs/wamp
  */
 public static function wamp($class_name = null)
 {
     /**
      * Check class name
      */
     if (!class_exists($class_name)) {
         static::help();
         exit;
     }
     $config = \Ratchet::get_config($class_name);
     /**
      * Check port
      */
     if (!is_numeric($config['port'])) {
         static::help();
         exit;
     }
     /**
      * Check zmq port
      */
     if (!is_numeric($config['zmq_port'])) {
         static::help();
         exit;
     }
     $loop = \React\EventLoop\Factory::create();
     $class = new $class_name();
     /**
      * Listen for the web server to make a ZeroMQ push after an ajax request
      */
     $context = new \React\ZMQ\Context($loop);
     $pull = $context->getSocket(\ZMQ::SOCKET_PULL);
     // Binding to 127.0.0.1 means the only client that can connect is itself
     $pull->bind('tcp://127.0.0.1:' . $config['zmq_port']);
     $pull->on('message', array($class, 'zmqCallback'));
     /**
      * Set up our WebSocket server for clients wanting real-time updates
      */
     $socket = new \React\Socket\Server($loop);
     // Binding to 0.0.0.0 means remotes can connect
     $socket->listen($config['port'], '0.0.0.0');
     $server = new \Ratchet\Server\IoServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($class)), $socket);
     $loop->run();
 }
Esempio n. 26
0
<?php

require_once "../vendor/autoload.php";
$loop = \React\EventLoop\Factory::create();
$context = new \React\ZMQ\Context($loop);
$listener = $context->getSocket(ZMQ::SOCKET_PULL);
$listener->bind('tcp://127.0.0.1:5559');
$listener->on('message', function ($msg) {
    echo " + - - - - - - - - - + \n";
    echo "       RESULTS         \n";
    print_r($msg);
    echo "\n + - - - - - - - - - + \n\n";
});
$loop->run();
Esempio n. 27
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$req = $context->getSocket(ZMQ::SOCKET_REQ);
$req->connect('tcp://127.0.0.1:5555');
$i = 0;
$loop->addPeriodicTimer(1, function () use(&$i, $req) {
    $i++;
    switch (mt_rand(1, 3)) {
        case 1:
            $subject = 'Автомобили';
            break;
        case 2:
            $subject = 'Электроника';
            break;
        case 3:
            $subject = 'Спорт';
            break;
    }
    printf('Отправил запрос [%d] | Тема сообщения [%s]' . PHP_EOL, $i, $subject);
    $req->send(sprintf('%s %d', $subject, $i));
});
$req->on('message', function ($msg) use($req) {
    printf('Получил ответ [%s]' . PHP_EOL, $msg);
});
$loop->run();
Esempio n. 28
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$sender = $context->getSocket(ZMQ::SOCKET_PUSH);
$sender->bind('tcp://127.0.0.1:5557');
$i = 0;
$loop->addPeriodicTimer(1, function () use(&$i, $sender) {
    $i++;
    echo "Отправил сообщение [{$i}]", PHP_EOL;
    $sender->send($i);
});
$loop->run();