提示:

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;}```

更多相关文章

  1. Linux服务器查看PHP是否支持mail()函数方法
  2. php实现共享内存进程通信函数之shm
  3. php date函数时间不对
  4. 【docker+gdb】调试 PHP 源码,看 strval 函数 C 实现
  5. php中base64加密解密函数实例(附代码)
  6. PHP错误处理函数
  7. PHP自动加载机制介绍——spl_autoload_register()函数,php类自动
  8. PHP如何为函数执行设置超时
  9. PHP二维数组按照指定的字段排序的函数

随机推荐

  1. ajax - 使用onload和onunload开始和结束
  2. PHP实现快速排序
  3. PHP文件锁同步实例
  4. weiphp插件开发注意
  5. 《细说PHP》第一章 LAMP网站的构建---读
  6. 如何将多行数据插入到一个表字段中
  7. 从文本文件中读取,然后决定是否要在php中
  8. 我的includes / header.php中的引用CSS文
  9. thinkphp执行删除操作然后成功success后
  10. 从数组中回显键和值