Redis::subscribe PHP Method

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
        public static function subscribe($channels, $callback, $connection = null, $method = 'subscribe')
        {
            \Illuminate\Redis\Database::subscribe($channels, $callback, $connection, $method);
        }

Usage Example

<?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');
All Usage Examples Of Redis::subscribe