Пример #1
0
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;
}
Пример #2
0
 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);
 }
Пример #3
0
 public function __construct()
 {
     $this->servers = 0;
     $this->sequence = 0;
     $this->context = new ZMQContext();
     $this->socket = $this->context->getSocket(ZMQ::SOCKET_DEALER);
 }
Пример #4
0
 /**
  * Отправка данных на сервер
  *
  * @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));
 }
Пример #5
0
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");
    }
}
Пример #6
0
/**
 * 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));
}
Пример #7
0
 /**
  * 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);
             });
         }
     }
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 /**
  * 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);
 }
Пример #10
0
 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;
     //}
 }
Пример #11
0
 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;
 }
Пример #12
0
 /**
  * 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');
 }
Пример #13
0
 /**
  * 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));
 }
Пример #14
0
 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);
 }
Пример #15
0
 protected function _initSockets()
 {
     $bindRouterSocketTo = $this->_config->get('sockets.queueManager');
     $context = new \ZMQContext();
     $routerSocket = $context->getSocket(\ZMQ::SOCKET_ROUTER);
     $routerSocket->bind($bindRouterSocketTo);
     $this->_socket = $routerSocket;
 }
 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);
 }
Пример #17
0
 /**
  * @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;
 }
Пример #18
0
 static function factory($socket)
 {
     $context = new \ZMQContext();
     $dealer = $context->getSocket(\ZMQ::SOCKET_DEALER);
     $queue = new Client($dealer);
     $queue->setSocket($socket);
     return $queue;
 }
 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));
 }
Пример #20
0
 public static function factory($socket)
 {
     $context = new \ZMQContext();
     $socketDealer = $context->getSocket(\ZMQ::SOCKET_DEALER);
     $queueServer = new Server($socketDealer);
     $queueServer->setSocket($socket);
     return $queueServer;
 }
Пример #21
0
 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);
 }
Пример #22
0
 /**
  * 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());
 }
Пример #23
0
 /**
  * Connect to ZMQ Socket.
  *
  * @return mixed
  */
 protected function connectToZmq()
 {
     $host = Config::get('socket.zmqHost', 'localhost');
     $port = Config::get('socket.zmqPort', '5555');
     $persistentId = Config::get('socket.socketPushId', 'paxifi.zmq.push');
     $ctx = new \ZMQContext();
     $socket = $ctx->getSocket(\ZMQ::SOCKET_PUSH, $persistentId);
     $socket->connect("tcp://{$host}:{$port}");
     return $socket;
 }
Пример #24
0
 /**
  * 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;
 }
Пример #25
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));
}
Пример #26
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;
 }
Пример #27
0
 private function __setupPub()
 {
     $context = new ZMQContext();
     $pub = $context->getSocket(ZMQ::SOCKET_PUB);
     $port = Configure::read('Plugin.ZeroMQ_port');
     if (empty($port)) {
         $port = 50000;
     }
     $pub->bind("tcp://*:" . $port);
     return $pub;
 }
Пример #28
0
 /**
  * @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;
 }
Пример #29
0
 private function forkRepWorker()
 {
     $pid = pcntl_fork();
     if ($pid != 0) {
         return $pid;
     }
     $context = new \ZMQContext();
     $rep = $context->getSocket(\ZMQ::SOCKET_REP);
     $rep->connect('ipc://test2.ipc');
     $msg = $rep->recv();
     $rep->send($msg . 'bar');
     exit;
 }
Пример #30
0
 public function testAction()
 {
     $session = $this->get('session')->getId();
     $entryData = array('hash' => $session, 'CMD' => "look", 'article' => "kittensCategory", 'when' => time());
     // This is our new stuff
     $context = new \ZMQContext();
     $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
     $socket->connect("tcp://localhost:5555");
     $socket->send(json_encode($entryData));
     $data = array();
     $data['hash'] = $session;
     return $this->render('RottenwoodUtopiaMudBundle:Default:test.html.twig', $data);
 }