记录php5.4与php-redis冲突的解决
[error] 29229#0: *1403 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server:
不知道所云。后来打开php-fpm错误日志,得到的log日志
[08-Oct-2013 21:22:23] WARNING: [pool www] child 12026 exited on signal 11 (SIGSEGV - core dumped) after 5.997917 seconds from start
[08-Oct-2013 21:22:23] NOTICE: [pool www] child 12034 started
可以确定的一点,是php-fpm在一个时间点后重启了一个进程。还是毫无头绪。在网上搜了一大遍,有个有用的跟踪方法。
1、设置php-fpm,只起一个work进程
2、重启php-fpm, 执行ps aux| grep php-fpm 得到work进程号pid
3、strace -p pid
下面是我得到的信息
getcwd("/home/www/wms2.xxxx.com", 4096) = 26
lstat("/home/www/wms2.xiaomi.com/./RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xiaomi.com/protected/vendor/wms/api/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xiaomi.com/protected/vendor/wms/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xiaomi.com/protected/extensions/log/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xiaomi.com/protected/modules/rights/components/RWebUser.php", {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0
lstat("/home/www/wms2.xiaomi.com/protected/modules/rights/components", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
lstat("/home/www/wms2.xiaomi.com/protected/modules/rights", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
lstat("/home/www/wms2.xiaomi.com/protected/modules", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
open("/home/www/wms2.xiaomi.com/protected/modules/rights/components/RWebUser.php", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0
mmap(NULL, 2945, PROT_READ, MAP_SHARED, 5, 0) = 0x7fd9b4804000
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd9b442f000
munmap(0x7fd9b4804000, 2945) = 0
close(5) = 0
getcwd("/home/www/wms2.xxx.com", 4096) = 26
lstat("/home/www/wms2.xxx.com/./XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/vendor/wms/api/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/vendor/wms/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/extensions/log/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/modules/rights/components/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/modules/rights/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)
lstat("/home/www/wms2.xxx.com/protected/components/XMCCacheHttpSession.php", {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0
open("/home/www/wms2.xxx.com/protected/components/XMCCacheHttpSession.php", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0
mmap(NULL, 2612, PROT_READ, MAP_SHARED, 5, 0) = 0x7fd9b4804000
munmap(0x7fd9b4804000, 2612) = 0
close(5) = 0
sendto(4, "get 6cacd9674ad21aa083b5032b1a29"..., 39, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 39
recvfrom(4, 0x2806d88, 8196, 64, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=4, events=POLLIN}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "VALUE 6cacd9674ad21aa083b5032b1a"..., 8196, MSG_DONTWAIT, NULL, NULL) = 128
lstat("/home/www/wms2.xxx.com/yii/web/CHttpCookie.php", {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0
lstat("/home/www/wms2.xxx.com/yii/web", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
open("/home/www/wms2.xxx.com/yii/web/CHttpCookie.php", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0
mmap(NULL, 2772, PROT_READ, MAP_SHARED, 5, 0) = 0x7fd9b4804000
munmap(0x7fd9b4804000, 2772) = 0
close(5) = 0
stat("/home/www/wms2.xxx.com/protected/extensions/redis/XMRedis.php", {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
lstat("/home/www/wms2.xxx.com/protected/extensions/redis/XMRedis.php", {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
lstat("/home/www/wms2.xxx.com/protected/extensions/redis", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
lstat("/home/www/wms2.xxx.com/protected/extensions", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
open("/home/www/wms2.xxx.com/protected/extensions/redis/XMRedis.php", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
fstat(5, {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0
mmap(NULL, 2672, PROT_READ, MAP_SHARED, 5, 0) = 0x7fd9b4804000
munmap(0x7fd9b4804000, 2672) = 0
close(5) = 0
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 5
close(5) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 5
fcntl(5, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(5, {sa_family=AF_INET, sin_port=htons(22122), sin_addr=inet_addr("10.237.36.231")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=5, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 3000) = 1 ([{fd=5, revents=POLLOUT}])
getsockopt(5, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl(5, F_SETFL, O_RDWR) = 0
setsockopt(5, SOL_TCP, TCP_NODELAY, [1], 4) = 0
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
sendto(5, "*2\r\n$4\r\nAUTH\r\n$9\r\nxm_wms_rs\r\n", 29, MSG_DONTWAIT, NULL, 0) = 29
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 3000) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "+OK\r\n", 8192, MSG_DONTWAIT, NULL, NULL) = 5
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
Process 6011 detached
可以看得出,在执行XMRedis后进程6011 就死掉了。基本可以定位是php-redis出了问题。
继续追查最终发现了有段代码问题
public function conn() {
try {
$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("xm_wms_rs");
$this->connected = true;
} catch (RedisException $e) {
throw new CHttpException(500, "Redis occurs an error:" . $e->getMessage());
}
}
用红色的代码那段,就会报502错误,而用绿色代码这段就没问题。
setOption 这个是个神马东西呢?查了下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
为什么用php内置的序列化就会出错呢?到底发生了什么?
后来又安装了IGBINARY 扩展,还是不行。最后把php-redis安装了最新的版本2.24,再运行,就完全没问题了。
推荐阅读
-
Android 中ScrollView与ListView冲突问题的解决办法
-
Android 中ScrollView与ListView冲突问题的解决办法
-
Android ListView与ScrollView冲突的解决方法总结
-
wifi精灵与闪讯冲突的详细解决办法
-
解决自定义$(id)的方法与jquery选择器$冲突的问题
-
asp.net开发与web标准的冲突问题的一些常见解决方法
-
html文件中jquery与velocity变量中的$冲突的解决方法
-
python3.8与pyinstaller冲突问题的快速解决方法
-
android基础教程之android的listview与edittext冲突解决方法
-
电脑硬件资源的冲突与解决方法