博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
缓存服务器 之 Linux下缓存服务器的应用
阅读量:6880 次
发布时间:2019-06-26

本文共 1936 字,大约阅读时间需要 6 分钟。

作者:tonyvicky

来自:LinuxSir.Org
摘要:由于数据库存储的数据量越来越大,查询速度也就变的越来越慢,因此就有了缓存服务器应用的必要,本文是介绍Memcached的安装以及简单的使用。

本文只介绍memcached的PHP的API,想查看其他关于Memcached的API文档案,请访问 http://www.danga.com/memcached/

目录

++++++++++++++++++++++++++++++++++++++++
正文
++++++++++++++++++++++++++++++++++++++++

一、环境需求

安装Memcached需要libevent库的支持,所以请在安装Memcached之前检查有没有安装libevent。测试环境还需要PHP的支持,本文假设PHP已经安装到/usr/local/php目录下,也就是在编译PHP的时候使用perfix参数指定目录(--prefix=/usr/local/php)

二、下载相关软件

Memcached下载地址:http://www.danga.com/memcached/

memcache PHP模块下载地址: http://pecl.php.net/package/memcache 推荐使用1.5版
libevent 下载地址: http://www.monkey.org/~provos/libevent/

本文不再讲述如何安装libevent

三、安装和配置

1、安装Memcached

root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install

安装完之后要启动服务

root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root

参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行

2、安装memcache PHP模块

root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install

安装完后会有类似这样的提示:

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

把这个记住,然后修改php.ini,把

extension_dir = "./"

修改为

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"

并添加一行

extension=memcache.so

3、测试脚本

自己写一个PHP程序测试一下吧

<?php
$memcache
= new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;
?>
四、关于本文
......

转载于:https://www.cnblogs.com/licheng/archive/2008/01/23/1050149.html

你可能感兴趣的文章
JAVA生成四位数的验证码
查看>>
讯飞语音错误码大全
查看>>
编译器错误消息: CS0433: The type 'global_asax' exists in both 'App_global.asax
查看>>
原生ajax显示php后台内容
查看>>
Android 富文本装饰器Spannable
查看>>
sync.Map源码分析
查看>>
error: invalid storage class for function
查看>>
seci-log 1.08 发布 增加snmp trap v2c和v3的收集
查看>>
AWK 文件处理计数
查看>>
通过libvirt使用ceph块设备
查看>>
优秀交互设计师成长指南
查看>>
SDN网络系统之MiniNet的安装与使用
查看>>
WPF中Image控件的Source属性的设置
查看>>
体绘制(Volume Rendering)概述之4:光线投射算法(Ray Casting)实现流程和代码(基于CPU的实现)...
查看>>
Python实践之(七)逻辑回归(Logistic Regression)
查看>>
PAT (Advanced Level) 1107. Social Clusters (30)
查看>>
POJ 3494 Largest Submatrix of All 1’s
查看>>
Ubuntu系统分配存储空间的建议以及给Ubuntu系统根目录扩容方法(从20GB追加100GB)...
查看>>
centos 查询mysql配置文件位置
查看>>
Eclipse IDE 使用技巧(一)
查看>>