Home php教程 php手册 记录php5.4与php-redis冲突的解决

记录php5.4与php-redis冲突的解决

Jun 21, 2016 am 08:48 AM
nbsp php protected quot redis

最近由于update了ubuntu的源,导致原来新源与本地系统库一些lib冲突,导致系统桌面显示异常,后来只有重装,新安装了php5.4.9,还安装了redis,php-redis扩展,php-redis扩展2,10。但把原来的项目一放上去,就报nginx 502错误(nginx 502错误真是个很头疼的问题)。打开nginx日志查看

 

[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_IFREG0777, st_size=2945, ...}) = 0

 

lstat("/home/www/wms2.xiaomi.com/protected/modules/rights/components", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

lstat("/home/www/wms2.xiaomi.com/protected/modules/rights", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

lstat("/home/www/wms2.xiaomi.com/protected/modules", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

open("/home/www/wms2.xiaomi.com/protected/modules/rights/components/RWebUser.php", O_RDONLY) = 5

 

fstat(5, {st_mode=S_IFREG0777, st_size=2945, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2945, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2945, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2945, ...}) = 0

 

mmap(NULL, 2945, PROT_READ, MAP_SHARED, 5, 0) = 0x7fd9b4804000

 

mmap(NULL, 266240, PROT_READPROT_WRITE, MAP_PRIVATEMAP_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_IFREG0777, st_size=2612, ...}) = 0

 

open("/home/www/wms2.xxx.com/protected/components/XMCCacheHttpSession.php", O_RDONLY) = 5

 

fstat(5, {st_mode=S_IFREG0777, st_size=2612, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2612, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2612, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, 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_DONTWAITMSG_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_IFREG0777, st_size=2772, ...}) = 0

 

lstat("/home/www/wms2.xxx.com/yii/web", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

open("/home/www/wms2.xxx.com/yii/web/CHttpCookie.php", O_RDONLY) = 5

 

fstat(5, {st_mode=S_IFREG0777, st_size=2772, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2772, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2772, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, 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_IFREG0777, st_size=2672, ...}) = 0

 

lstat("/home/www/wms2.xxx.com/protected/extensions/redis/XMRedis.php", {st_mode=S_IFREG0777, st_size=2672, ...}) = 0

 

lstat("/home/www/wms2.xxx.com/protected/extensions/redis", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

lstat("/home/www/wms2.xxx.com/protected/extensions", {st_mode=S_IFDIR0777, st_size=4096, ...}) = 0

 

open("/home/www/wms2.xxx.com/protected/extensions/redis/XMRedis.php", O_RDONLY) = 5

 

fstat(5, {st_mode=S_IFREG0777, st_size=2672, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2672, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, st_size=2672, ...}) = 0

 

fstat(5, {st_mode=S_IFREG0777, 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_RDWRO_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=POLLINPOLLOUTPOLLERRPOLLHUP}], 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=POLLINPOLLPRIPOLLERRPOLLHUP}], 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=POLLINPOLLPRIPOLLERRPOLLHUP}], 1, 0) = 0 (Timeout)

 

poll([{fd=5, events=POLLINPOLLERRPOLLHUP}], 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,再运行,就完全没问题了。

 



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Laravel8 optimization points Laravel8 optimization points Apr 18, 2025 pm 12:24 PM

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.

Redis's Role: Exploring the Data Storage and Management Capabilities Redis's Role: Exploring the Data Storage and Management Capabilities Apr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot? What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot? Apr 19, 2025 pm 08:03 PM

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Title: How to use Composer to solve distributed locking problems Title: How to use Composer to solve distributed locking problems Apr 18, 2025 am 08:39 AM

Summary Description: Distributed locking is a key tool for ensuring data consistency when developing high concurrency applications. This article will start from a practical case and introduce in detail how to use Composer to install and use the dino-ma/distributed-lock library to solve the distributed lock problem and ensure the security and efficiency of the system.

See all articles