手记

linux安装memcache及php测试是否成功

linux memcache安装教程,让你快速使用memcache缓存服务器
        1 下载好3个安装包memcached-1.4.14.tar.gz,libevent-2.0.20-stable.tar.gz,memcached-1.4.14.tar.gz

  2 安装libevent

  tar -zxf libevent-2.0.20-stable.tar.gz

  cd libevent-2.0.20-stable

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

  make

  make install

  3 安装memcached

  tar -zxf memcached-1.4.14.tar.gz

  cd memcache-1.4.14

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

  make

  make install

  安装好后 可以把/usr/local/memcached/bin/memcached

  4 启动memcached服务器

  /usr/local/memcached/bin/memcached -d -m 10 -u root -l 192.168.0.14 -p 11211 -c 64 -P /tmp/memcached.pid

  参数左右

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

  -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,

  -u是运行Memcache的用户,我这里是root,

  -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,

  -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,

  -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,

  -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

  设置软链

  ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib/libevent-2.0.so.5

  5 将memcache载入php扩展中

  tar vxzf memcache-2.2.7.tgz

  cd memcache-2.2-7

  /usr/local/php/bin/phpize

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

  make

  make install

  如果phpize没找到 安装 yum install php-devel

  接着出现这样提示

  Installing shared extensions :/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

  6 修改php.ini

  1 将extension_dir="./" 修改为extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

  2 extension=memcache.so

  3 重启apache

  7 测试

  $mem = new Memcache;

$mem->connect('192.168.0.14',11211) or die('memcache connect failed');

$key='select * from part_tab limit 10';

$data = $mem->get($key);

if(!$data){

$con = mysql_connect('localhost','root','root') or die('mysql connect failed');

mysql_select_db('test',$con);

$result = mysql_query($key);

while($row = mysql_fetch_assoc($result)){

$data[]=$row;}

$mem->set($key,$data,3600);

echo 'ok';

}else{

print_r($data);

}


0人推荐
随时随地看视频
慕课网APP