taoCMS是基于php+sqlite/mysql的国内最小(100Kb左右)的功能完善、开源免费的CMS管理系统

解决连接redis时Fatal error: Uncaught exception ‘RedisException’ with message ‘read error on connection’

2012-03-29

原代码

#!/usr/bin/php -q
/**
 * This is a demo
 * @see docchatserver
 */
//ini_set('default_socket_timeout', -1);
$redis = new Redis();
$redis->pconnect('127.0.0.1',6379);
$redis->select(15);
 
function channel($redis, $channel, $msg) {
    echo 'from-' . $channel . ':' . $msg . "n";
}
 
$redis->subscribe(array('world', 'city', 'union', 'firend'), 'channel');
?>

执行上面代码无任何消息时触发Fatal error: Uncaught exception ‘RedisException’ with message ‘read error on connection’,查看redis扩展源码发现扩展连接redis服务器使用默认php的socket方式,查看php.ini设置了default_socket_timeout = 60,所以没有任何消息时出现了上面的错误,解决方法是加入

ini_set('default_socket_timeout', -1);

上面的代码可以应用在游戏消息通知方面,需要注意的是redis服务器配置中timeout的设置

修改redis.conf, timeout 设为0

类别:技术文章 | 阅读:972861 | 评论:2 | 标签:redis

想收藏或者和大家分享这篇好文章→

“解决连接redis时Fatal error: Uncaught exception ‘RedisException’ with message ‘read error on connection’”共有1条留言

  1. 玎当 @2012-11-06 05:20 回复

    谢谢了

发表评论

姓名:

邮箱:

网址:

验证码:

公告

taoCMS发布taoCMS 3.0.2(最后更新21年03月15日),请大家速速升级,欢迎大家试用和提出您宝贵的意见建议。

捐助与联系

☟请使用新浪微博联系我☟

☟在github上follow我☟

标签云