The settlement of record php5.4 and Php-redis conflict

Source: Internet
Author: User
Tags fpm log log log lstat redis socket connection reset yii
Recently, due to the update of the ubuntu source, the original new source and the local system library lib conflict, resulting in the system desktop display exception, and later only reload, new installation of php5.4.9, also installed redis, php-redis extension, php- Redis extension 2.10. But put the original project one, it will report nginx 502 error (nginx 502 error is really a headache). Open nginx log view

[error] 29229#0: *1403 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server:

I don't know what it is. Later open the php-fpm error log and get the log 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

One thing that can be determined is that php-fpm restarts a process after a point in time. Still no clue. Searched online a lot, there is a useful tracking method.

1, set php-fpm, only one work process

2, restart php-fpm, execute ps aux| grep php-fpm get the work process number pid

3, strace -p pid

Below is the information I got.

Getcwd("/home/www/xxx", 4096) = 26

Lstat("/home/www/xxx/./RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/vendor/wms/api/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/vendor/wms/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/extensions/log/RWebUser.php", 0x7ffff4e30a10) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/modules/rights/components/RWebUser.php", {st_mode=S_IFREG|0777, st_size=2945, ...}) = 0

Lstat("/home/www/xxx/protected/modules/rights/components", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Lstat("/home/www/xxx/protected/modules/rights", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Lstat("/home/www/xxx/protected/modules", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Open("/home/www/xxx/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/xxx", 4096) = 26

Lstat("/home/www/xxx/./XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/vendor/wms/api/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/vendor/wms/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/extensions/log/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/modules/rights/components/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/modules/rights/XMCCacheHttpSession.php", 0x7ffff4e31060) = -1 ENOENT (No such file or directory)

Lstat("/home/www/xxx/protected/components/XMCCacheHttpSession.php", {st_mode=S_IFREG|0777, st_size=2612, ...}) = 0

Open("/home/www/xxx/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/xxx/yii/web/CHttpCookie.php", {st_mode=S_IFREG|0777, st_size=2772, ...}) = 0

Lstat("/home/www/xxx/yii/web", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Open("/home/www/xxx/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/xxx/protected/extensions/redis/XMRedis.php", {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0

Lstat("/home/www/xxx/protected/extensions/redis/XMRedis.php", {st_mode=S_IFREG|0777, st_size=2672, ...}) = 0

Lstat("/home/www/xxx/protected/extensions/redis", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Lstat("/home/www/xxx/protected/extensions", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0

Open("/home/www/xxx/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



It can be seen that the process 6011 died after executing XMRedis. Basically, it can be positioned that php-redis has a problem.

Continue to trace and finally found a piece of code problem



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("xxxrs");



$this->connected = true;



} catch (RedisException $e) {

Throw new CHttpException(500, "Redis occurs an error:" . $e->getMessage());

}

}

With the red code, you will get a 502 error, and with the green code, there is no problem.



setOption Is this a god horse thing? Checked the php-redis api



$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data does not serialize data

$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize Serialization with php built-in

$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize Serialize with extended IGBINARY

$redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys redis key prefix



$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); Use this to report 502



Why use php built-in serialization will go wrong? In the end what happened?

Later, the IGBINARY extension was installed, or not. Finally, php-redis installed the latest version 2.24, and then run, it is no problem.
————————————————
Copyright statement: This article is the original article of CSDN blogger "Yi Guang Nian", following the CC 4.0 BY-SA copyright agreement, please reprint the original source link and this statement.
Original link: https://blog.csdn.net/tengzhaorong/article/details/12704759


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.