wget http://download.redis.io/releases/redis-3.0.5.tar.gz
tar xzf redis-3.0.5.tar.gz
cd redis-3.0.5
make
./src/redis-server &
./src/redis-server ./redis.conf
wget http://pecl.php.net/get/redis-2.2.7.tgz , 本文选择2.2.7版本
tar zxvf redis-2.2.7.tgz
cd redis-2.2.7
/opt/server/php-5.5.7/bin/phpize
./configure
make
make install
extension=/opt/server/php-5.5.7/lib/php/extensions/no-debug-non-zts-20121212/redis.so
/opt/server/nginx/sbin/nginx -s reload
kill -USR2 `cat /opt/server/php-5.5.7/var/run/php-fpm.pid`
cd /www/html/basic
php composer.phar require --prefer-dist yiisoft/yii2-redis
在components数组中添加如下内容:
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
$redis = Yii::$app->redis;
$redis->get('key');
$redis->set('k','v');
basic/vendor/yiisoft/yii2-redis/Connection.php文件的源码中265行开始(因实际而定)
变量 errorNumber 、errorDescription ,没提前定义Yii2 一直报undefined
“@”把报错屏蔽了,一直查不到原因,删掉”@”才发现stream_socket_client、stream_socket_server()这两个函数禁用了
更改前
$this->_socket = @stream_socket_client(
$this->unixSocket ? 'unix://' . $this->unixSocket : 'tcp://' . $this->hostname . ':' . $this->port,
$errorNumber,
$errorDescription,
$this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout")
);
更改后
//也可以不定义这两个变量,通常项目都会忽略notice报错,视实际情况而定
$errorNumber = '';
$errorDescription = '';
//----如果报错:Warning:stream_socket_server() has been disabled for security reasons... 请看下面解决方法
//----这里"@" ↓↓↓ 把报错屏蔽了,需要删除"@"才能看见上面的报错,
$this->_socket = stream_socket_client(
$this->unixSocket ? 'unix://' . $this->unixSocket : 'tcp://' . $this->hostname . ':' . $this->port,
$errorNumber, //----这两个变量没有提前定义一直报undefined
$errorDescription, //----这两个变量没有提前定义一值报undefined
$this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout")
);
解决方法:编辑php.ini把disable_functions=…中找到stream_socket_server()、stream_socket_client删除并保存,重启web组件即可