public function __construct() { $this->servers = 0; $this->sequence = 0; $this->context = new ZMQContext(); $this->socket = $this->context->getSocket(ZMQ::SOCKET_DEALER); }
/** * @return \ZMQSocket */ private function getSocket() { if (null == $this->pushSocket) { $this->pushSocket = $this->context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $this->pushSocket->connect("tcp://localhost:5555"); } return $this->pushSocket; }
/** * Connects to the given endpoint */ public function connect() { $this->context = new \ZMQContext(); $this->socket = $this->context->getSocket(\ZMQ::SOCKET_PULL); if ($this->isDebug()) { ConsoleLog::log("Connecting to zmq at '{$this->getZmq()}'"); } $this->socket->connect($this->getZmq()); }
/** * @param $socketType * @param array $options * @param bool $justCreate * @return \ZMQSocket */ protected function createSocket($socketType, array $options = [], $justCreate = false) { $socket = $this->context->getSocket($socketType); foreach ($options as $key => $value) { $socket->setSockOpt($key, $value); } if (!$justCreate) { $this->socket = $socket; } return $socket; }
protected function _initSockets() { $this->log('starting to initialize sockets'); $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PAIR); $socket->connect(sprintf('ipc:///tmp/downloader-%d.ipc', $this->_downloadBundleId)); $this->_socketToWorker = $socket; $socket = $context->getSocket(\ZMQ::SOCKET_DEALER); $socket->setSockOpt(\ZMQ::SOCKOPT_IDENTITY, sprintf('downloader/%s', uniqid())); $socket->connect($this->_config->get('sockets.queueManager')); $this->_socketToQueueManager = $socket; $this->_context = $context; $this->log('initialized sockets'); }
public function __construct($sender_id, $sub_addr, $pub_addr) { $this->sender_id = $sender_id; $ctx = new \ZMQContext(); $reqs = $ctx->getSocket(\ZMQ::SOCKET_UPSTREAM); $reqs->connect($sub_addr); $resp = $ctx->getSocket(\ZMQ::SOCKET_PUB); $resp->connect($pub_addr); $resp->setSockOpt(\ZMQ::SOCKOPT_IDENTITY, $sender_id); $this->sub_addr = $sub_addr; $this->pub_addr = $pub_addr; $this->reqs = $reqs; $this->resp = $resp; }
function attack() { $db = JFactory::getDBO(); $user = JFactory::getUser(); $id = JRequest::getvar('id'); $monster = $this->getMonster($id, $db); $player = $this->getPlayer($user, $db); $attackRoundMonster = $monster->defence + rand(0, 6); $attackRoundPlayer = $monster->attack + rand(0, 6); if ($attackRoundPlayer > $attackRoundMonster) { $query = "UPDATE #__jigs_monsters SET health = health -10 WHERE id= {$id}"; $db->setQuery($query); $db->query(); $message = 'You caused 10 hit points of damage'; MessagesHelper::sendFeedback($user->id, $message); } $query = "SELECT health FROM #__jigs_monsters WHERE id= {$id}"; $db->setQuery($query); $result['id'] = $id; $result['health'] = $db->loadResult(); $entryData = array('category' => 'monsterHealthCategory', 'title' => 'title', 'article' => $result, 'when' => time()); $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher'); if ($socket->connect("tcp://localhost:5555")) { // echo 'connected'; } if ($socket->send(json_encode($entryData))) { // echo 'delivered'; } return true; }
/** * Execute the job. * * @return void */ public function handle() { $reader = Reader::createFromPath($this->path); $read = 0; $saved = 0; foreach ($reader->fetchAssoc() as $row) { $read++; $artist = Artist::firstOrNew(['artist_id' => $row['artist_id']]); $artist->artist_id = $row['artist_id']; $artist->slug = $row['slug']; $artist->name = $row['name']; $artist->PID = $row['PID']; $artist->year_birth = $row['year_birth']; $artist->year_death = $row['year_death']; $artist->copyright = $row['copyright']; if ($artist->save()) { $saved++; } } $report = ['event' => 'artists.imported', 'data' => ['read' => $read, 'saved' => $saved]]; $message = json_encode($report); $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send($message); }
/** * Отправка данных на сервер * * @param array $data */ static function sendDataToServer(array $data) { $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send(json_encode($data)); }
/** * @return void */ protected function init() { $this->logger->info("Running " . self::class . " on " . str_replace("\n", "", `hostname; echo ' - ';uname -a;`)); $this->logger->info("The eviction tick rate is set to {$this->config->getEvictionTicksPerSec()}/second."); // Create the event loop $this->reactLoop = React\EventLoop\Factory::create(); // Object pool $this->queue = new PriorityHashQueue(); // In default mode the latest data will be replaced for a given key. In DATA_MODE_APPEND the data will be appended // internally and available within the consumer as array (for instance for reducing purposes) //$this->queue->setDataMode(PriorityHashQueue::DATA_MODE_APPEND); // Setup ZMQ to send evicted objects. $this->zmqContext = new React\ZMQ\Context($this->reactLoop); $this->logger->info("Binding inbound ZMQ to '{$this->config->getZmqIn()}'."); // Receiver queue for incoming objects $this->zmqInboundQueue = $this->zmqContext->getSocket(\ZMQ::SOCKET_PULL); $this->zmqInboundQueue->bind($this->config->getZmqIn()); $this->logger->info("Binding outbound ZMQ to '{$this->config->getZmqOut()}'."); // Outgoing queue for evicted objects $this->zmqOutboundQueue = $this->zmqContext->getSocket(\ZMQ::SOCKET_PUSH); $this->zmqOutboundQueue->bind($this->config->getZmqOut()); // Register events $this->registerInboundEvents(); $this->registerEvictionEvents(); $this->registerTimedEvents(); }
/** * Execute the job. * * @return void */ public function handle(MergeManager $mergeManager, FileManager $fileManager) { $columns = ['PID', 'entity type', 'title', 'document type', 'URL', 'enabled', 'notes', 'format', 'reference', 'order']; $items = $mergeManager->fetchAll(); $writer = Writer::createFromFileObject(new SplTempFileObject()); $writer->insertOne($columns); $count = 0; foreach ($items as $item) { $row = [$item->object_number, $item->entity_type, $item->object->title, $item->url, $item->enabled, $item->format, $item->representation_order, $item->reference]; $writer->insertOne($row); $count++; } $output = (string) $writer; $timestamp = Carbon::now(); $fileName = sprintf("import_%s.csv", $timestamp->format('dmY_His')); $fileManager->saveFile($fileName, $output); $merger = new Merger(); $merger->filename = $fileName; $merger->documents = $count; $merger->save(); $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send('test'); }
/** * Execute the job. * * @return void */ public function handle() { $reader = Reader::createFromPath($this->path); $read = 0; $saved = 0; foreach ($reader->fetchAssoc() as $row) { $read++; $object_number = $row['object_number']; unset($row['object_number']); foreach ($row as $key => $value) { $document = Document::firstOrNew(['url' => $value]); $document->object_number = $object_number; $document->url = $value; if ($key == "data") { $document->type = "data"; $document->order = ""; } else { list($type, $order) = explode("_", $key); $document->type = $type; $document->order = isset($order) ? $order : ""; } if ($document->save()) { $saved++; } } } $report = ['event' => 'documents.imported', 'data' => ['read' => $read, 'saved' => $saved]]; $message = json_encode($report); $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send($message); }
function initialize() { global $config, $queue; /* Load the config. Create a publishing socket. */ // Danger! Danger! $json = shell_exec("fedmsg-config"); $config = json_decode($json, true); /* Just make sure everything is sane with the fedmsg config */ if (!array_key_exists('relay_inbound', $config)) { echo "fedmsg-config has no 'relay_inbound'"; return false; } $context = new ZMQContext(1, true); $queue = $context->getSocket(ZMQ::SOCKET_PUB, "pub-a-dub-dub"); $queue->setSockOpt(ZMQ::SOCKOPT_LINGER, $config['zmq_linger']); if (is_array($config['relay_inbound'])) { // API for fedmsg >= 0.5.2 // TODO - be more robust here and if connecting to the first one fails, try // the next, and the next, and etc... $queue->connect($config['relay_inbound'][0]); } else { // API for fedmsg <= 0.5.1 $queue->connect($config['relay_inbound']); } # Go to sleep for a brief moment.. just long enough to let our zmq socket # initialize. if (array_key_exists('post_init_sleep', $config)) { usleep($config['post_init_sleep'] * 1000000); } return true; }
/** * Send real-time notifications to subscribed users * * @param string $hook Hook name * @param string $type Hook type * @param bool $result Has anyone sent a message yet? * @param array $params Hook parameters * @return bool * @access private */ function wizmass_notifier_notification_send($hook, $type, $result, $params) { /** @var WizmassNotifier\Interfaces\WizmassNotification $notification */ $notification = $params['notification']; //echo 'got notification: ' . $notification->guid . PHP_EOL; //$ia = elgg_set_ignore_access(true); //echo 'got subjects: ' . count($notification->getSubjects()) . PHP_EOL; //elgg_set_ignore_access($ia); require __DIR__ . '/vendor/autoload.php'; $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $subjects = []; foreach ($notification->getSubjects() as $subject) { $subjects[] = array('guid' => $subject->guid); } $msg = new \stdClass(); $msg->recipient_guids = $subjects; //$msg->recipient_guid = $recipient->guid; // $msg->subject_name = $actor->getDisplayName(); // $msg->subject_url = $actor->getURL(); // $msg->target_name = $entity->getDisplayName(); // $msg->target_url = $entity->getURL(); // $msg->text = $string; // $msg->icon_url = $actor->getIconURL(); $msg->data = $notification->BuildNotificationData(); //echo 'encoded notification data: ' . json_encode($msg) . PHP_EOL; $socket->send(json_encode($msg)); }
function worker_thread() { $context = new ZMQContext(); $worker = $context->getSocket(ZMQ::SOCKET_REQ); $worker->connect("ipc://backend.ipc"); // Tell broker we're ready for work $worker->send("READY"); while (true) { // Read and save all frames until we get an empty frame // In this example there is only 1 but it could be more $address = $worker->recv(); // Additional logic to clean up workers. if ($address == "END") { exit; } $empty = $worker->recv(); assert(empty($empty)); // Get request, send reply $request = $worker->recv(); printf("Worker: %s%s", $request, PHP_EOL); $worker->send($address, ZMQ::MODE_SNDMORE); $worker->send("", ZMQ::MODE_SNDMORE); $worker->send("OK"); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $config = Config::get('announcements-server.mailer'); // Listen for mailer workers. $mailer = 'tcp://' . $config['ip'] . ':' . $config['port']; $this->info('Connecting mailer worker to ' . $mailer); $context = new ZMQContext(); $mailerSocket = $context->getSocket(ZMQ::SOCKET_REP); $mailerSocket->bind($mailer); while (true) { $msg = $mailerSocket->recv(); $mailerSocket->send('OK'); $msg = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $msg); // Ignore late alerts. if (!$msg->isFuture()) { continue; } $users = User::where('announcements', 1)->get(); foreach ($users as $user) { Mail::send('emails.announcement', array('date' => $msg), function ($message) use($user) { $message->to($user->email); }); } } }
private function initSocket() { $zmq_context = new \ZMQContext(); $this->zmq_socket = $zmq_context->getSocket(\ZMQ::SOCKET_REP); $this->zmq_socket->bind('ipc:///tmp/ebussola-job-schedule.ipc'); chmod('/tmp/ebussola-job-schedule.ipc', 0777); }
function update_pos() { $db = JFactory::getDBO(); $user = JFactory::getUser(); $posx = JRequest::getVar('posx'); $posy = JRequest::getVar('posy'); $query = "UPDATE #__jigs_players SET posx = '{$posx}',posy = '{$posy}' WHERE id ='{$user->id}'"; $db->setQuery($query); $db->query(); // $monsters = $this->get_monsters( $this->get_coord()['grid']); $players = $this->get_playersPos($this->get_coord()['grid']); /* $entryData = array( 'category' => 'kittensCategory', 'title' => 'title', 'article' => $monsters, 'when' => time() ); */ $entryData = array('category' => 'playersCategory', 'title' => 'title', 'article' => $players, 'when' => time()); $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher'); if ($socket->connect("tcp://localhost:5555")) { // echo 'connected'; } if ($socket->send(json_encode($entryData))) { echo 'sent'; } $db->setQuery($query); $db->query(); return $query; //} }
static function factory($socket) { $context = new \ZMQContext(); $dealer = $context->getSocket(\ZMQ::SOCKET_DEALER); $queue = new Client($dealer); $queue->setSocket($socket); return $queue; }
public function notifySocketServer() { $encodedGame = $this->gameEncoder->getLiteObject(); $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'game pusher'); $socket->connect($this->socketAddress); $socket->send($encodedGame); }
protected function _initSockets() { $bindRouterSocketTo = $this->_config->get('sockets.queueManager'); $context = new \ZMQContext(); $routerSocket = $context->getSocket(\ZMQ::SOCKET_ROUTER); $routerSocket->bind($bindRouterSocketTo); $this->_socket = $routerSocket; }
/** * Send data to server * * @param array $data */ static function sendDataToServer(array $data) { $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $port = env('WEBSOCKET_PORT', 5555); $socket->connect('tcp://127.0.0.1:' . $port); $socket->send(json_encode($data)); }
public function testGetLoadedJobsSocket() { $zmq_context = new \ZMQContext(); $zmq_socket = $zmq_context->getSocket(\ZMQ::SOCKET_REQ); $zmq_socket->connect('ipc:///tmp/ebussola-job-schedule.ipc'); $response = unserialize($zmq_socket->send('get loaded jobs')->recv()); $this->assertCount(5, $response); }
public static function emit($channel, $body = null, string $socketId = null) { $JSON = array('channel' => $channel, 'body' => $body, 'socketId' => $socketId); $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH); $socket->connect("tcp://127.0.0.1:5555"); return $socket->send(json_encode($JSON)); }
public static function factory($socket) { $context = new \ZMQContext(); $socketDealer = $context->getSocket(\ZMQ::SOCKET_DEALER); $queueServer = new Server($socketDealer); $queueServer->setSocket($socket); return $queueServer; }
public function loop() { list($sender_id, $sub_addr, $pub_addr) = $this->pieces; $ctx = new \ZMQContext(); $this->reqs = $ctx->getSocket(\ZMQ::SOCKET_UPSTREAM); $this->reqs->connect($sub_addr); $this->resp = $ctx->getSocket(\ZMQ::SOCKET_PUB); $this->resp->connect($pub_addr); $this->resp->setSockOpt(\ZMQ::SOCKOPT_IDENTITY, $sender_id); $this->in_loop = true; while ($this->in_loop) { declare (ticks=1) { $message = $this->reqs->recv(); } call_user_func($this->callback, array($message, $this->resp), null); pcntl_signal_dispatch(); } }
public function __construct($username, $password, $method = \Phirehose::METHOD_SAMPLE, $format = self::FORMAT_JSON, $lang = FALSE) { $context = new \ZMQContext(); $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'hadoch'); $socket->connect("tcp://localhost:5555"); $this->zmq = $socket; $this->log = new SimpleLogger(SimpleLogger::DEBUG, BASE_PATH . '/track.log'); parent::__construct($username, $password, $method, $format, $lang); }
/** * Execute the command by requesting it over the ZMQ socket * * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $context = new \ZMQContext(); $push = $context->getSocket(\ZMQ::SOCKET_REQ); $push->connect('tcp://127.0.0.1:5560'); $push->send(json_encode(['cmd' => $this->command->getName(), 'params' => $this->getParams($input)])); $response = $push->recv(); $output->writeln($response); return 0; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $context = new \ZMQContext(); $push = $context->getSocket(\ZMQ::SOCKET_REQ); $push->connect('tcp://127.0.0.1:5560'); $push->send($this->getNodeCommand()); $response = $push->recv(); $output->writeln($response); return 0; }
function callback($value, $data) { $bricklet = $data[0]; $type = $data[1]; $entryData = array('topic' => "tinkerforge", 'value' => $value, 'bricklet' => $bricklet, 'type' => $type, 'time' => time()); $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send(json_encode($entryData)); }