本文整理汇总了PHP中ZMQContext类的典型用法代码示例。如果您正苦于以下问题:PHP ZMQContext类的具体用法?PHP ZMQContext怎么用?PHP ZMQContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ZMQContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initialize
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;
}
开发者ID:bugcy013,项目名称:fedora_ansible,代码行数:31,代码来源:fedmsg-emit.php
示例2: initSocket
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);
}
开发者ID:ebussola,项目名称:job-schedule,代码行数:7,代码来源:Daemon.php
示例3: __construct
public function __construct()
{
$this->servers = 0;
$this->sequence = 0;
$this->context = new ZMQContext();
$this->socket = $this->context->getSocket(ZMQ::SOCKET_DEALER);
}
开发者ID:inactivist,项目名称:zguide,代码行数:7,代码来源:flclient2.php
示例4: sendDataToServer
/**
* Отправка данных на сервер
*
* @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));
}
开发者ID:a1ex7,项目名称:librauth,代码行数:12,代码来源:Pusher.php
示例5: worker_thread
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");
}
}
开发者ID:inactivist,项目名称:zguide,代码行数:25,代码来源:lbbroker.php
示例6: wizmass_notifier_notification_send
/**
* 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));
}
开发者ID:roybirger,项目名称:elgg-wizmass-notifier,代码行数:39,代码来源:start.php
示例7: fire
/**
* 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);
});
}
}
}
开发者ID:fencer-md,项目名称:stoticlle,代码行数:30,代码来源:AnnouncementsMailer.php
示例8: handle
/**
* 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);
}
开发者ID:netsensei,项目名称:resin,代码行数:38,代码来源:importDocuments.php
示例9: handle
/**
* 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);
}
开发者ID:netsensei,项目名称:resin,代码行数:31,代码来源:importArtists.php
示例10: update_pos
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;
//}
}
开发者ID:yatan,项目名称:JiGS-PHP-RPG-engine,代码行数:32,代码来源:map.php
示例11: attack
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;
}
开发者ID:Rai-Ka,项目名称:JiGS-PHP-RPG-engine,代码行数:31,代码来源:monsters.php
示例12: handle
/**
* 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');
}
开发者ID:netsensei,项目名称:resin,代码行数:30,代码来源:Merge.php
示例13: sendDataToServer
/**
* 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));
}
开发者ID:BinaryStudioAcademy,项目名称:reviewr,代码行数:13,代码来源:Pusher.php
示例14: notifySocketServer
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);
}
开发者ID:richardlawson,项目名称:coinflip,代码行数:8,代码来源:GameUpdateNotifier.php
示例15: _initSockets
protected function _initSockets()
{
$bindRouterSocketTo = $this->_config->get('sockets.queueManager');
$context = new \ZMQContext();
$routerSocket = $context->getSocket(\ZMQ::SOCKET_ROUTER);
$routerSocket->bind($bindRouterSocketTo);
$this->_socket = $routerSocket;
}
开发者ID:sgraebner,项目名称:tp,代码行数:8,代码来源:QueueManager.php
示例16: testGetLoadedJobsSocket
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);
}
开发者ID:ebussola,项目名称:job-schedule,代码行数:8,代码来源:ExternalControllerCommandTest.php
示例17: factory
static function factory($socket)
{
$context = new \ZMQContext();
$dealer = $context->getSocket(\ZMQ::SOCKET_DEALER);
$queue = new Client($dealer);
$queue->setSocket($socket);
return $queue;
}
开发者ID:gonzalo123,项目名称:zmqlifo,代码行数:8,代码来源:Client.php
示例18: emit
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));
}
开发者ID:silverstripe-supervillains,项目名称:silverstripe-origami,代码行数:8,代码来源:ZMQInterface.php
示例19: factory
public static function factory($socket)
{
$context = new \ZMQContext();
$socketDealer = $context->getSocket(\ZMQ::SOCKET_DEALER);
$queueServer = new Server($socketDealer);
$queueServer->setSocket($socket);
return $queueServer;
}
开发者ID:gonzalo123,项目名称:zmqlifo,代码行数:8,代码来源:Server.php
示例20: __construct
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);
}
开发者ID:uzulla,项目名称:hadogun2,代码行数:9,代码来源:Collector.php
注:本文中的ZMQContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论