php7出了!性能提升一倍!
不过兼容性好像还不太好,我在php7下安装memcached扩展遇到了问题,记录一下。
centos下安装php7见 http://my.oschina.net/u/150705/blog/473836 与安装5.6基本类似。
1. 首先使用yum安装memcache:
yum search memcached
yum -y install memcached
安装成功之后输入
memcached -h 可以查看memcached的命令参数,之后可以通过如下的命令来启动memcached:
memcached -d -m 100 -u root -l 192.168.0.100 -p 11211 -c 512 -P /tmp/memcached.pid
参数说明如下:
-d选项是启动一个守护进程;
-m是分配给memcache使用的内存数量,单位是mB,我这里是100mB;
-u是运行memcache的用户,我这里是root;
-l是监听的服务器IP地址我这里指定了服务器的IP地址192.168.0.100;
-p是设置memcache监听的端口,我这里设置了11211,最好是1024以上的端口;
-c选项是最大运行的并发连接数,默认是1024,我这里设置了512,按照你服务器的负载量来设定;
-P是设置保存memcache的pid文件,我这里是保存在 /tmp/memcached.pid; 也可以通过如下命令来启动,此时各参数为默认值:
service memcached start
2. memcache关联php:
yum -y install php-pecl-memcache 然后是安装php的memcache扩展,注意有两个memcache扩展,一个叫memcache,一个叫memcached,前者较老,一般使用后者:
安装php的memcached扩展:
pecl install memcache 然而报错,显然pecl之中没有收录可用于php7的memcached扩展,只能手动安装:
pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0, excluded versions: 6.0.0), installed version is 7.0.0 No valid packages found 3. 手动安装php的memcached扩展:
安装这个扩展,需要安装libmemcached支持:
官网在此,找到最新版的下载链接 https://launchpad.net/libmemcached,使用wget下载tar.gz压缩包,解压缩,进入目录,依次执行(prefix后为安装目录):
./configure --prefix=/usr/local/libmemcached --with-memcached
make
make install 然后安装memcached,在php官网(http://pecl.php.net/package/memcached)找到memcached的最新下载链接,同样使用wget下载tar.gz压缩包,解压缩,进入目录,依次执行(其中php-config和libmemcached目录根据具体情况设定):
phpize
./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached
make
make install 然而在执行make install的时候报错,提示缺少php_smart_str.h,看来memcached不支持php7:
/bin/sh /data/tmp/memcached-2.2.0/libtool --mode=compile cc -I/data/soft/php7/include/php -I. -I/data/tmp/memcached-2.2.0 -DPHP_ATOM_INC -I/data/tmp/memcached-2.2.0/include -I/data/tmp/memcached-2.2.0/main -I/data/tmp/memcached-2.2.0 -I/data/soft/php7/include/php -I/data/soft/php7/include/php/main -I/data/soft/php7/include/php/TSRM -I/data/soft/php7/include/php/Zend -I/data/soft/php7/include/php/ext -I/data/soft/php7/include/php/ext/date/lib -I/data/soft/libmemcached/include -DHAVE_CONFIG_H -g -O2 -c /data/tmp/memcached-2.2.0/php_memcached.c -o php_memcached.lo mkdir .libs cc -I/data/soft/php7/include/php -I. -I/data/tmp/memcached-2.2.0 -DPHP_ATOM_INC -I/data/tmp/memcached-2.2.0/include -I/data/tmp/memcached-2.2.0/main -I/data/tmp/memcached-2.2.0 -I/data/soft/php7/include/php -I/data/soft/php7/include/php/main -I/data/soft/php7/include/php/TSRM -I/data/soft/php7/include/php/Zend -I/data/soft/php7/include/php/ext -I/data/soft/php7/include/php/ext/date/lib -I/data/soft/libmemcached/include -DHAVE_CONFIG_H -g -O2 -c /data/tmp/memcached-2.2.0/php_memcached.c -fPIC -DPIC -o .libs/php_memcached.o In file included from /data/tmp/memcached-2.2.0/php_memcached.c:26:0: /data/tmp/memcached-2.2.0/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory #include ^ compilation terminated. make: *** [php_memcached.lo] Error 1 具体情况继续关注中