[TOC] ## demo server.php ``` $redis = new Redis(); if ( ! $redis->connect('127.0.0.1', 6379)) { die($redis->getLastError()); } $redis->publish("chat", "123"); ``` client.php ``` $redis = new Redis(); if ( ! $redis->connect('127.0.0.1', 6379)) { die($redis->getLastError()); } $redis->set("count", "1"); print_r($redis->get("count")); function f($redis, $chan, $msg) { switch($chan) { case 'chat': print_r($msg); break; case 'chan-2': break; case 'chan-2': break; } } while (true){ $redis->subscribe(array('chat', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans sleep(1); } ``` 执行 1.`php client.php` 2.`php server.php`