1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux php安装memcached扩展

linux php安装memcached扩展

时间:2021-04-22 22:34:09

相关推荐

linux php安装memcached扩展

linux php安装memcached扩展

在linux 编译,需要gcc,make,cmake,autoconf,libtool 等工具,需提前安装好。

memcached的安装包括:1、服务端的安装;2、客户端的安装

一、服务器端安装

方法一:

memcached 依赖于libevent 库,因此我们需要先安装libevent.

假设将源码放在/usr/local/src

1 cd /usr/local/src2 wget /libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz3 tar zxvf libevent-2.0.22-stable.tar.gz4 cd libevent-2.0.22-stable5 ./configure --prefix=/usr/local/libevent6 make && make install

安装memcached服务器版

1 cd /usr/local/src2 wget /files/memcached-1.4.33.tar.gz3 tar zxvf memcached-1.4.33.tar.gz4 cd memcached-1.4.335 ./configure --prefix=/usr/local/memcached \6 --with-libevent=/usr/loca/libevent7 make && make install

启动memcached

1 /usr/local/memcached/bin/memcached -m 64 -p 11211 -u nobody -vv

显示如上说明memcached服务器端安装启动成功并把信息输出到控制台

想后台运行加-d选项

1 /usr/local/memcached/bin/memcached -m 64 -p 11211 -u nobody -d

1 ps aux | grep memcached

查询进程是否有memcached

启动成功

方法二:

1 yum -y install memcached

就这一步我们就安装完了

启动memcached

1 /usr/bin/memcached -l 127.0.0.1 -p 11211 -m 150 -u root

显示如方法二启动结果

二、客户端安装

客户端需安装libmemcached库

1 cd /usr/local/src2 wget /libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz3 tar zxvf libmemcached-1.0.18.tar.gz4 cd libmemcached-1.0.185 ./configure --prefix=/usr/local/libmemcached6 make && make install

安装php-fpm的memcached扩展

1 cd /usr/local/src2 wget /get/memcached-2.2.0.tgz3 tar zxvf memcached-2.2.0.tgz4 cd memcached-2.2.0

到了这一步,我们要使用安装php时生成的 phpize 来生成 configure 配置文件

1 /usr/local/php/bin/phpize \2 --with-php-config=/usr/local/php/bin/php-config3 ./configure --with-php-config=/usr/local/php/bin/php-config \4 --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl5 make && make install

--with-php-config 指定 php-config,该文件与 phpize 所在目录相同,

--with-libmemcached-dir 指定 libmemcached 安装目录,就刚才我们 --prefix 那个目录 ,

--disable-memcached-sasl 说明我们系统不支持sasl.h

如果安装成功,会提示:Installing shared extension:/usr/local/php/lib/extensions/no-debug-non-zts-0524/ 等类信息

接下来,我们编辑php配置文件php.ini,把 php-memcached 扩展加到配置文件。

在 php.ini 中添加以下内容:

1 extension=memcached.so

最后重启nginx和php-fpm

重启完之后,检查是否安装完成php-memcached扩展

在nginx的web根目录下创建一个test.php文件

1 <?php2phpinfo();3 ?>

在浏览器中输入服务器ip地址

以上说明memcached的php扩展安装成功以。

php其他扩展均可根据此方法安装。

使用php简单操作memcached

其实 memcached 和 redis 、MySQL是没什么两样,同是数据库,(redis是非关系数据库,mysql是关系数据库),因此使用也是差不多的,同样具有命令行使用和php操作使用,关于memcached的更多命令大家可以自行百度。

1 <?php 23$mem=new Memcached(); //实例化Memcached类 4$server=array( 5 array('127.0.0.1',11211), 6); 7$mem->addServers($server); 8 9$mem->set('name','zhangsan',15); ////设置缓存值,有效时间3600秒,如果有效时间设置为0,则表示该缓存值永久存在的(系统重启前)10echo $mem->get('name');11 12 ?>

来源:/flywind/p/6021568.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。