PHP 构建使用 igbinary 作为序列化组件的 memcached 模块
无论是从 PECL 安装 php5-memcached 还是从 apt-get 命令安装,安装上的 memcached 模块都是不带有 igbinary 序列化组件支持的,由于 igbinary 有很大的性能优势,所以尽量使用 igbinary 作为 memcached 的序列化组件。
环境说明
操作系统:Ubuntu Server 14.04 64-bit
PHP:PHP 5.5.9
构建过程
首先,安装 PHP 开发版
yuanyu@usvr:~$ sudo apt-get install php5-dev
然后安装依赖库
yuanyu@usvr:~$ sudo apt-get install libevent-dev
yuanyu@usvr:~$ sudo apt-get install pkg-config
接下来,安装 igbinary 模块
yuanyu@usvr:~$ sudo pecl install igbinary
从源码构建 libmemcached
获取 libmemcached 的源码,这里使用的是 1.0.18 版本
yuanyu@usvr:~$ cd tmp
yuanyu@usvr:~/tmp$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
解压缩,配置,并且进行构建
yuanyu@usvr:~/tmp$ tar xzvf libmemcached-1.0.18.tar.gz
yuanyu@usvr:~/tmp$ cd libmemcached-1.0.18
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ ./configure
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ make
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ sudo make install
从源码构建 php5-memcached
使用 pecl 获取 php5-memcached 的源码,然后配置的时候启用 --enable-memcached-igbinary。
yuanyu@usvr:~/tmp$ pecl download memcached-2.2.0
yuanyu@usvr:~/tmp$ tar xzvf memcached-2.2.0.tgz
yuanyu@usvr:~/tmp$ cd memcached-2.2.0
yuanyu@usvr:~/tmp/memcached-2.2.0$ phpize
yuanyu@usvr:~/tmp/memcached-2.2.0$ ./configure --enable-memcached-igbinary --disable-memcached-sasl
yuanyu@usvr:~/tmp/memcached-2.2.0$ make
yuanyu@usvr:~/tmp/memcached-2.2.0$ sudo make install
配置 PHP,加入新构建的两个模块
上面的构建步骤完成之后,就会在 PHP 扩展模块产生 2 个 so 文件:igbinary.so 和 memcached.so,将这个两个文件配置到你的运行环境中即可。
下面我们来看一篇关于 安装php的parsekit扩展查看opcode的操作教程希望这篇文章能够对各位带来帮助,具体的如下。我们知道PHP是一门解释型语言,用它们编写的动态内容都需要依赖相应的解释器程序来运行,解释器程序需要对输入的脚本代码进行分析,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode)。
想要查看php程序的opcode,需要安装php的parsekit扩展。
安装过程如下:
[root@localhost ~]# wget http://pecl.php.net/get/parsekit-1.3.0.tgz
[root@localhost ~]# tar zxvf parsekit-1.3.0.tgz
[root@localhost ~]# cd parsekit-1.3.0
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
[root@localhost parsekit-1.3.0]# ./configure -with-php-config=/usr/local/php/bin/php-config
[root@localhost parsekit-1.3.0]# make
[root@localhost parsekit-1.3.0]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
然后编辑php.ini文件,在里面加上
extension="parsekit.so"
[root@localhost parsekit-1.3.0]# vim /usr/local/php/etc/php.ini
这样我们就成功的安装了parsekit扩展了(注:楼主是在php5.2下安装的parsekit扩展,在php5.4,php5.5下会提示编译失败)。
当然还有一种更简单的安装parsekit的方法,那就是直接使用pecl。
在命令行下输入命令:
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/pecl install parsekit
这样就可以自动帮你安装parsekit了。
然后,我们在命令行下输入:
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/php -r "var_dump(parsekit_compile_string('print 1+1;'));"
这样就可以查看php代码的opcode了。
结果如下:
array(20) {
["type"]=>
int(4)
["type_name"]=>
string(14) "ZEND_EVAL_CODE"
["fn_flags"]=>
int(0)
["num_args"]=>
int(0)
["required_num_args"]=>
int(0)
["pass_rest_by_reference"]=>
bool(false)
["uses_this"]=>
bool(false)
["line_start"]=>
int(0)
["line_end"]=>
int(0)
["return_reference"]=>
bool(false)
["refcount"]=>
int(1)
["last"]=>
int(5)
["size"]=>
int(5)
["T"]=>
int(2)
["last_brk_cont"]=>
int(0)
["current_brk_cont"]=>
int(4294967295)
["backpatch_count"]=>
int(0)
["done_pass_two"]=>
bool(true)
["filename"]=>
string(17) "Parsekit Compiler"
["opcodes"]=>
array(5) {
[0]=>
array(8) {
["address"]=>
int(29981148)
["opcode"]=>
int(1)
["opcode_name"]=>
string(8) "ZEND_ADD"
["flags"]=>
int(197378)
["result"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(0)
}
["op1"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&int(1)
}
["op2"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&int(1)
}
["lineno"]=>
int(1)
}
[1]=>
array(7) {
["address"]=>
int(29981268)
["opcode"]=>
int(41)
["opcode_name"]=>
string(10) "ZEND_PRINT"
["flags"]=>
int(770)
["result"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(1)
}
["op1"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(0)
}
["lineno"]=>
int(1)
}
[2]=>
array(7) {
["address"]=>
int(29981388)
["opcode"]=>
int(70)
["opcode_name"]=>
string(9) "ZEND_FREE"
["flags"]=>
int(271104)
["op1"]=>
array(4) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(1)
["EA.type"]=>
int(0)
}
["op2"]=>
array(3) {
["type"]=>
int(8)
["type_name"]=>
string(9) "IS_UNUSED"
["opline_num"]=>
string(1) "0"
}
["lineno"]=>
int(1)
}
[3]=>
array(7) {
["address"]=>
int(29981508)
["opcode"]=>
int(62)
["opcode_name"]=>
string(11) "ZEND_RETURN"
["flags"]=>
int(16777984)
["op1"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&NULL
}
["extended_value"]=>
int(0)
["lineno"]=>
int(1)
}
[4]=>
array(5) {
["address"]=>
int(29981628)
["opcode"]=>
int(149)
["opcode_name"]=>
string(21) "ZEND_HANDLE_EXCEPTION"
["flags"]=>
int(0)
["lineno"]=>
int(1)
}
}
}
编译安装配置
wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar zxvf xhprof-0.9.4.tgz
cd xhprof-0.9.4
cd extension/
/usr/bin/phpize
./configure
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/etc/php.ini
EOF<<<
[xhprof]
extension=xhprof.so;
xhprof.output_dir=/home/wwwroot/iamle.com/xhprof
EOF
mkdir -p /home/wwwroot/iamle.com/xhprof
cd ..
cp -rv examples/ xhprof_html/ xhprof_lib/ /home/wwwroot/iamle.com/xhprof
/etc/init.d/php-fpm reload
例子用法
http://localhost/xhprof/examples/sample.php
http://localhost/xhprof/xhprof_html/index.php?run=5455f9208a2eb&source=xhprof_foo
xhprof的名词解释
Function Name 函数名
Calls 调用次数
Calls% 调用百分比
Incl. Wall Time (microsec) 调用的包括子函数所有花费时间 以微秒算(一百万分之一秒)
IWall% 调用的包括子函数所有花费时间的百分比
Excl. Wall Time (microsec) 函数执行本身花费的时间,不包括子树执行时间,以微秒算(一百万分之一秒)
EWall% 函数执行本身花费的时间的百分比,不包括子树执行时间
Incl. CPU(microsecs) 调用的包括子函数所有花费的cpu时间。减Incl. Wall Time即为等待cpu的时间
减Excl. Wall Time即为等待cpu的时间
ICpu% Incl. CPU(microsecs)的百分比
Excl. CPU(microsec) 函数执行本身花费的cpu时间,不包括子树执行时间,以微秒算(一百万分之一秒)。
ECPU% Excl. CPU(microsec)的百分比
Incl.MemUse(bytes) 包括子函数执行使用的内存。
IMemUse% Incl.MemUse(bytes)的百分比
Excl.MemUse(bytes) 函数执行本身内存,以字节算
EMemUse% Excl.MemUse(bytes)的百分比
Incl.PeakMemUse(bytes) Incl.MemUse的峰值
IPeakMemUse% Incl.PeakMemUse(bytes) 的峰值百分比
Excl.PeakMemUse(bytes) Excl.MemUse的峰值
EPeakMemUse% EMemUse% 峰值百分比
编译安装PHP7并安装Redis扩展Swoole扩展
在编译php7的机器上已经有编译安装过php5.3以上的版本,从而依赖库都有了
本php7是编译成fpm-php 使用的,
如果是apache那么编译参数应该为
--with-apxs2=/usr/local/apache/bin/apxs
编译安装php7
wget -c http://www.php.net/distributions/php-7.0.0.tar.gz
tar zxvf php-7.0.0.tar.gz
cd php-7.0.0
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir -\
-with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php7/etc/php.ini
cd ..
编译安装php7的redis扩展支持
wget -c https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip
cd phpredis-php7
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
cd ..
/usr/local/php7/etc/php.ini
中加入
extension=redis.so
编译安装php7的swoole
wget -c https://github.com/swoole/swoole-src/archive/swoole-1.7.21-stable.tar.gz
tar zxvf swoole-1.7.21-stable.tar.gz
cd swoole-src-swoole-1.7.21-stable/
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
cd ..
/usr/local/php7/etc/php.ini
中加入
extension=swoole.so
相关文章
Jackson反序列化@JsonFormat 不生效的解决方案
这篇文章主要介绍了Jackson反序列化@JsonFormat 不生效的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-08-10PHP分布式框架如何使用Memcache同步SESSION教程
本教程主要讲解PHP项目如何用实现memcache分布式,配置使用memcache存储session数据,以及memcache的SESSION数据如何同步。 至于Memcache的安装配置,我们就不讲了,以前...2016-11-25- memche消息队列的原理就是在key上做文章,用以做一个连续的数字加上前缀记录序列化以后消息或者日志。然后通过定时程序将内容落地到文件或者数据库。php实现消息队列的用处比如在做发送邮件时发送大量邮件很费时间的问...2014-05-31
- 这篇文章主要介绍了解决Golang json序列化字符串时多了\的情况,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-12-24
- 序列化是一种对象持久化的手段,普遍应用在网络传输、RMI等场景中,这篇文章主要给大家总结介绍了关于java序列化与反序列化的使用方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考下...2021-07-29
- 下面小编就为大家带来一篇protobuf对象二进制序列化存储(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 经常看到一些配置文件里面存放的是一些类似带有格式的变量名称和值,其实就是一个序列化的过程,在需要用到这些数据库的时候会进行一个反序列化过程,就是将这个字符串再还原成他原来的数据结构。下面说说php 如何进行数据...2015-10-30
- 这篇文章主要介绍了C#实现的json序列化和反序列化代码实例,本文讲解了两种实现方法,并直接给出代码示例,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#实现的序列化通用类,实例分析了C#序列化与反序列化操作相关技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了Jackson 反序列化时实现大小写不敏感设置方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-29
- 在这篇文章中,我们将会学到如何使用C#,来序列化对象成为Json格式的数据,以及如何反序列化Json数据到对象。...2020-06-25
- 这篇文章主要介绍了C#中Serializable序列化,以实例形式详细讲述了系列化的技术及各种序列化方法,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 下面小编就为大家带来一篇用序列化实现List<T> 实例的深复制(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 这篇文章主要介绍了C#实现复杂XML的序列化与反序列化的方法,是非常实用的一个技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了javascript中from 表单序列化提交的实现方法,代码简单易懂,非常不错,需要的朋友参考下吧...2017-01-23
- 很多phper不知道如何在Windows下搭建Memcache的开发调试环境,最近个人也在研究Memcache,记录下自己安装搭建的过程。 ...2016-01-27
在Mac OS的PHP环境下安装配置MemCache的全过程解析
这篇文章主要介绍了在Mac OS的PHP环境下安装配置MemCache的全过程解析,MemCache是一套分布式的高速缓存系统,需要的朋友可以参考下...2016-02-18深入分析XmlSerializer对象的Xml序列化与反序列化的示例详解
本篇文章是对XmlSerializer 对象的Xml序列化与反序列化的应用进行了详细的分析介绍,需要的朋友参考下...2021-09-22php memcache和php memcached比较以及问题
php memcache和php memcached是php的memcache分布式的高速缓存系统的两个客户端,php memcache是老客户端,php memcached是功能更加完善的新的代替php memcached的。...2016-11-25- 这篇文章主要介绍了Python实现序列化及csv文件读取,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-04-22