继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php-memcache 扩展

哆啦的时光机
关注TA
已关注
手记 75
粉丝 20
获赞 52

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。


首先需要先安装libevent,memcached是基于libevent做为事件触发的

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar zxvf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable

./configure --prefix=/usr/local/libevent

make && make install


接下来安装memecahed:

wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz

tar zxvf memcached-1.4.15.tar.gz

cd memcached-1.4.15

./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent

make && make install


安装php扩展模块memcache:

wget http://pecl.php.net/get/memcache-2.2.6.tgz

tar xzvf memcache-2.2.6.tgz

cd memcache-2.2.6

/usr/local/php/bin/phpize     -----执行phpize扩展安装程序,如果没有安装phpize  运行yum install php-devel

./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

make && make install


安装成功会有类似下面的提示

Installing shared extensions: /usr/local/php/lib/php/extensions/xxxxxxx。。。


在php.ini文件,在zend之前加入如下代码:

[memcache]

extension_dir = "/usr/local/php/lib/php/extensions/xxxxxxxx"

extension=memcache.so


启动memcached:

/usr/local/memcached/bin/memcached -d -u root -m 1024 -p 11211 -c 10240


如果php运行环境是apache需要重启apache,如果是nginx需要重启php这样能重新加载php配置文件来支持 memcache


启动参数说明:

  -d   选项是启动一个守护进程,

  -m  是分配给Memcache使用的内存数量,单位是MB,默认64MB

  -M  return error on memory exhausted (rather than removing items)

  -u  是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。

  -l   是监听的服务器IP地址,默认为所有网卡。

  -p  是设置Memcache的TCP监听的端口,最好是1024以上的端口

  -c  选项是最大运行的并发连接数,默认是1024

  -P  是设置保存Memcache的pid文件


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP