在components数组中添加如下内容:
'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'localhost', 'port' => 6379, 'database' => 0, ],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组件即可
