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數組中添加以下內容:php
'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行開始(因實際而定)css
變量 errorNumber 、errorDescription ,沒提早定義Yii2 一直報undefinedhtml
"@"把報錯屏蔽了,一直查不到緣由,刪掉"@"才發現stream_socket_client、stream_socket_server()這兩個函數禁用了nginx
更改前git
$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")
);
更改後github
//也能夠不定義這兩個變量,一般項目都會忽略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組件便可web