subscribe() public static method

Subscribe to a set of given channels for messages.
public static subscribe ( array | string $channels, Closure $callback, string $connection = null, string $method = 'subscribe' ) : void
$channels array | string
$callback Closure
$connection string
$method string
return void
Exemplo n.º 1
1
<?php

include_once 'helper.php';
include_once 'db.php';
ini_set('default_socket_timeout', -1);
function userinfo_chan($msg)
{
    $pubMsg = json_decode($msg, true);
    $db = new DB();
    $db->updateUser($pubMsg);
}
function subscribe_handler($redis, $chan, $msg)
{
    print_r($msg . "---\r\n");
    helper_log("redis submsg: " . $msg);
    switch ($chan) {
        case 'userinfo_chan':
            userinfo_chan($msg);
            break;
        case 'chan-2':
            break;
        case 'chan-3':
            break;
    }
}
$redis = new Redis();
$redis->connect('127.0.0.1', 6380);
$redis->subscribe(array('userinfo_chan'), 'subscribe_handler');
Exemplo n.º 2
0
 /**
     Subscribe which takes Channel and promotes to Array if String
     @param $ch Channel or Array of Channels
     @param $cb Callback String or array($this,'cbMethod');
 */
 function subscribe($ch, $cb)
 {
     if (is_string($ch)) {
         $ch = array($ch);
     }
     return parent::subscribe($ch, $cb);
 }
Exemplo n.º 3
0
 /**
  * @param string|string[] $channels
  * @param Closure         $callback
  */
 public function subscribe($channels, Closure $callback)
 {
     $channels = (array) $channels;
     $this->_subscribeCallback = $callback;
     $this->_redis->setOption(Redis::OPT_READ_TIMEOUT, 86400 * 100);
     $this->_redis->subscribe($channels, array($this, '_subscribeCallback'));
 }
Exemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \Redis::subscribe('demeterMiddle', function ($message) {
         $m = json_decode($message);
         echo var_dump($m);
         dispatch(new \App\Jobs\handleVmRequest($m));
     });
 }
Exemplo n.º 5
0
<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$channel = $argv[1];
// channel
$redis->subscribe(array('channel' . $channel), 'callback');
function callback($instance, $channelName, $message)
{
    echo $channelName, "==>", $message, PHP_EOL;
}