redis发布订阅通知基于socket,连接超时受配置影响,可以修改php.ini,或者动态添加
ini_set('default_socket_timeout', -1);
pub.php
```$redis = new redis();// 第一个参数为redis服务器的ip,第二个为端口$res = $redis->connect('127.0.0.1', 6379);// test为发布的频道名称,hello,world为发布的消息$res = $redis->publish('test','hello,world');```
sub.php
```$redis = new redis();$res = $redis->connect('127.0.0.1', 6379,0);$redis->subscribe(array('test'), 'callback');// 回调函数,这里写处理逻辑function callback($instance, $channelname, $message) { echo $channelname, "==>", $message,php_eol;}```
以上就是php+redis发布订阅的详细内容。
