Solution to php redis502 error: 1. Use "sudo apt-get install php5-redis" or download phpredis on gitHub; 2. Recompile and install.
The operating environment of this article: Windows 7 system, PHP version 5.5.30, DELL G3 computer
How to solve the php redis502 error problem?
php redis set nginx 502 solution
PHP Version 5.5.30-1+deb.sury.org~trusty+1 redis 3.0.1,
The php-redis extension installed by downloading pr.tar.gz, version 2.10.
Execute $redis->set('test', 'hello world') and report nginx 502 error (nginx 502 error is really a headache).
The problem is located in $this->_redis->setOption(Redis::OPT_SERIALIZER,Redis::SERIALIZER_PHP);
Reason It is php-redis extension version 2.10. If it is too low, you can use sudo apt-get install php5-redis or download
https://github.com/phpredis/phpredis
on gitHub and install it through compilation.
apt-get install The installed version is 2.2.7.
public function conn() {undefined try {undefined $this->_redis->pconnect($this->host, $this->port, $this->timeout); // Set client option. must AFTER connected //var_dump(Redis::OPT_SERIALIZER,Redis::SERIALIZER_PHP);exit(); $this->_redis->setOption(Redis::OPT_SERIALIZER,Redis::SERIALIZER_PHP); //$this->_redis->setOption(0, 0); $this->_redis->auth("xxxrs"); // 此处是为 redis 配置的验证密码 $this->connected = true; } catch (RedisException $e) {undefined throw new CHttpException(500, "Redis occurs an error:" . $e->getMessage()); } }
If you use the red code section, a 502 error will be reported. There is no problem with the green code section.
setOption Is this a weird thing? Checked php-redis api
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data 不序列化数据 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize 用php内置的序列化 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize 用扩展IGBINARY序列化 $redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys redis key前缀 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); 用此就报502
Why does it go wrong when using PHP’s built-in serialization? In the end what happened?
Later I installed the IGBINARY extension, but it still didn’t work. Finally, I installed the latest version 2.24 of php-redis and ran it again, and there was no problem at all.
2.24 version php-redis source code address https://github.com/nicolasff/phpredis
== ====================
Redis::__construct constructor
$redis = new Redis( );
connect, open link redis service
Parameters
host: string, service address
port: int, port number
timeout: float, link duration (optional, default is 0, no limit to link time)
Note: There is also time in redis.conf, the default is 300
pconnect, popen will not Actively closed links
Refer to the above
setOption to set the redis mode
getOption to view the mode set by redis
ping to view the connection status
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve php redis502 error problem. For more information, please follow other related articles on the PHP Chinese website!