Home > php教程 > php手册 > body text

安装memcache和memcached

WBOY
Release: 2016-06-13 11:25:21
Original
1150 people have browsed it

   简单的说

    memcache是总的缓存系统项目名称,容易和php教程中的memcache混淆。

    我们常提到memcache其实是php中的memcache,即php的memcached扩展支持。

    我们常提到memcached是服务端主程序文件,服务端安装程序。

    为了让你的程序飞起来,必须安装memcached服务端程序和php的memcached扩展,所以如果您要使用memcache来缓存系统,memcache和memcached两样我们都需要安装。

    安装memcache

# cd /usr/local/src
# wget http://pecl.php.net/get/memcache-2.2.5.tgz
# gzip -d memcache-2.2.5.tgz
# tar xvf memcache-2.2.5.tar
# cd memcache-2.2.5 

    以下几句,是以php所在目录为/usr/local/php为例,如果您的php有变化,请自行替换几句中/usr/local/php的部分

# /usr/local/php/bin/phpize
# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make && make install 

    将memcache加入php扩展

    # vi /etc/php.ini(/etc/php.ini地址为我的php.ini位置,如果你不知道你的php.ini在哪里,可以用# find / -name php.ini进行查找,或者传个探针phpinfo,找到configuration file (php.ini) path)中php.ini的位置.

    末尾加入

    按键盘上的 i 开始编辑

    ctrl+f翻页拉到最下面在[zend]之前加入

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension=memcache.so 

    按esc键,再输入

    :wq

    保存退出

    重启你的web服务器,比如apache

/etc/init.d/httpd restart 

    下面刷新下php探针,看下是不是有这个了,有的话就是装好了

memcache
version  2.2.5memcache
version  2.2.5 

 

下面安装memcached

    装memcached首先需要安装安装libevent

    如果是centos可以yum安装

# yum install libevent-devel 

    如果不支持yum的系统,可以这样装libevent

# cd /usr/local/src
# wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
# tar vxf libevent-1.4.12-stable.tar.gz
# cd libevent-1.4.12
# ./configure --prefix=/usr/local/libevent
# make && make install 

    接续安装memcached

# cd /usr/local/src
# wget http://cloud.github.com/downloads/saberma/saberma.github.com/memcached-1.4.4.tar.gz
# tar vxf memcached-1.4.4.tar.gz
# cd memcached-1.4.4
# ./configure --prefix=/usr/local/memcached
# make && make install 

    安装完后启动memcached并分配32m内存(32为使用内存数,可按自身情况修改)

/usr/local/memcached/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root 

    将memcached加入启动项

# vi /etc/rc.d/rc.local 

    按键盘上的 i 开始编辑

    在最后加入

/usr/local/memcached/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root 

    按esc键,再输入

    :wq

    保存退出

    如果需要,可以reboot一下,不过不用reboot应该已经生效~

    加速效果测试

    用没有什么负载的discuz x1做个测试,未启用时

gmt+8, 2010-9-12 09:08, processed in 0.038893 second(s), 2 queries. 

    缓存启用后的效果,不过总体感觉vps教程上效果不如用eaccelerato缓存加入效果那么明显

gmt+8, 2010-9-12 09:08, processed in 0.008383 second(s), 2 queries, memcache on. 

    完成

下面安装memcached

    装memcached首先需要安装安装libevent

    如果是centos可以yum安装

# yum install libevent-devel 

    如果不支持yum的系统,可以这样装libevent

# cd /usr/local/src
# wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
# tar vxf libevent-1.4.12-stable.tar.gz
# cd libevent-1.4.12
# ./configure --prefix=/usr/local/libevent
# make && make install 

    接续安装memcached

# cd /usr/local/src
# wget http://cloud.github.com/downloads/saberma/saberma.github.com/memcached-1.4.4.tar.gz
# tar vxf memcached-1.4.4.tar.gz
# cd memcached-1.4.4
# ./configure --prefix=/usr/local/memcached
# make && make install 

    安装完后启动memcached并分配32m内存(32为使用内存数,可按自身情况修改)

/usr/local/memcached/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root 

    将memcached加入启动项

# vi /etc/rc.d/rc.local 

    按键盘上的 i 开始编辑

    在最后加入

/usr/local/memcached/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root 

    按esc键,再输入

    :wq

    保存退出

    如果需要,可以reboot一下,不过不用reboot应该已经生效~

    加速效果测试

    用没有什么负载的discuz x1做个测试,未启用时

gmt+8, 2010-9-12 09:08, processed in 0.038893 second(s), 2 queries. 

    缓存启用后的效果,不过总体感觉vps上效果不如用eaccelerato缓存加入效果那么明显

gmt+8, 2010-9-12 09:08, processed in 0.008383 second(s), 2 queries, memcache on. 

    完成


source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!