PHP code example of friendsofhyperf / redis-subscriber

1. Go to this page and download the library: Download friendsofhyperf/redis-subscriber library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

friendsofhyperf / redis-subscriber example snippets


$sub = new \FriendsOfHyperf\Redis\Subscriber\Subscriber('127.0.0.1', 6379, '', 5); // Connection failure will throw an exception
$sub->subscribe('foo', 'bar'); // Subscription failure will throw an exception

$chan = $sub->channel();
while (true) {
    $data = $chan->pop();
    if (empty($data)) { // Manual close or abnormal disconnection from Redis will return false
        if (!$sub->closed) {
            // Handle abnormal disconnection from Redis
            var_dump('Redis connection is disconnected abnormally');
        }
        break;
    }
    var_dump($data);
}