您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP+Redis发布订阅

2025/4/25 19:06:36发布20次查看
提示:
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发布订阅的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product