php配置memcached的扩展。
(一)安装memcached服务器
1根据系统下载相应版本的memcached服务器版本:如win7(64位=====》memcached-win64/memcached.exe
2、解压到目录:c:\mem (自定义,任何目录)
3、c:\mem\memcached.exe -d install
4 、c:\mem\memcached.exe -d start (启动服务)
5、telnet 127.0.0.1 11211 (使用telnet连接测试是否成功)

6、输入:stats 命令查看基本信息

具体解释:
memcached的基本命令(安装、卸载、启动、配置相关):
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
memcached的基本命令(当memcached 启动后 用于对memcached管理的数据和本身运行状态相关的命令):
|
Command |
Description |
Example |
|
get |
Reads a value |
get mykey |
|
set |
Set a key unconditionally |
set mykey 0 60 5 |
|
add |
Add a new key |
add newkey 0 60 5 |
|
replace |
Overwrite existing key |
replace key 0 60 5 |
|
append |
Append data to existing key |
append key 0 60 15 |
|
prepend |
Prepend data to existing key |
prepend key 0 60 15 |
|
incr |
Increments numerical key value by given number |
incr mykey 2 |
|
decr |
Decrements numerical key value by given number |
decr mykey 5 |
|
delete |
Deletes an existing key |
delete mykey |
|
flush_all |
Invalidate specific items immediately |
flush_all |
|
Invalidate all items in n seconds |
flush_all 900 |
|
|
stats |
Prints general statistics |
stats |
|
Prints memory statistics |
stats slabs |
|
|
Prints memory statistics |
stats malloc |
|
|
Print higher level allocation statistics |
stats items |
|
|
stats detail |
||
|
stats sizes |
||
|
Resets statistics |
stats reset |
|
|
version |
Prints server version. |
version |
|
verbosity |
Increases log level |
verbosity |
|
quit |
Terminate telnet session |
quit |
对查看的信息的关键字中英文对照表
|
pid |
memcache服务器的进程ID |
|
uptime |
服务器已经运行的秒数 |
|
time |
服务器当前的unix时间戳 |
|
version |
memcache版本 |
|
pointer_size |
当前操作系统的指针大小(32位系统一般是32bit) |
|
rusage_user |
进程的累计用户时间 |
|
rusage_system |
进程的累计系统时间 |
|
curr_items |
服务器当前存储的items数量 |
|
total_items |
从服务器启动以后存储的items总数量 |
|
bytes |
当前服务器存储items占用的字节数 |
|
curr_connections |
当前打开着的连接数 |
|
total_connections |
从服务器启动以后曾经打开过的连接数 |
|
connection_structures |
服务器分配的连接构造数 |
|
cmd_get |
get命令(获取)总请求次数 |
|
cmd_set |
set命令(保存)总请求次数 |
|
get_hits |
总命中次数 |
|
get_misses |
总未命中次数 |
|
evictions |
为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items) |
|
bytes_read |
总读取字节数(请求字节数) |
|
bytes_written |
总发送字节数(结果字节数) |
|
limit_maxbytes |
分配给memcache的内存大小(字节) |
|
threads |
当前线程数 |
(二)php配置memcached
(1)配置步骤
step1 下载php_memcache.dll组件,并将其放置到php的扩展组件目录,如:php\ext\
step2 在PHP.ini加入extension=php_memcache.dll后,重启Apache即可。
(2)在phpinfo()中查询memcache的是否安装。
(3) PHP中测试memcache:
<?php
//显示最近的文章前500条
$memcache_obj = new Memcache;
$memcache_obj->pconnect('localhost', 11211);
$article_id=$memcache_obj->get('article_id');
if($article_id==''){
$pdo = new PDO ("mysql:host=127.0.0.1;dbname=chinatupai","root","root");
$pdo->exec("set names gb2312");
$q=$pdo->query("select id,title from phphi_article order by id desc limit 500 ");
while($row=$q->fetch()){
$article_id[$row['id']]=$row['title'];//存储到数组中
}
$memcache_obj->set('article_id',$article_id, MEMCACHE_COMPRESSED, 0);
}
//查询id=2474的数据
$find_arr=$memcache_obj->get("article_id");
if($find_arr['2474']!=''){
echo $find_arr['2474'];
}else{
exit("内存中无此数据需要查询数据库!");
}?>
php配置memcached的扩展。的更多相关文章
- 转载:Centos7 从零编译配置Memcached
序言 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度. Memca ...
- [原创]Centos7 从零编译配置Memcached
序言 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度. Memca ...
- CentOS7 安装、配置 Memcached
点击访问原文地址 介绍 Memcached 是一个分布式.高性能的内存缓存系统,通过缓存内存中的数据和对象,提高和加速动态 web 应用程序的性能.它主要用于加速对数据库重度使用的站点. Memcac ...
- 如何配置Memcached高速缓存,加快wordpress的速度
Memcached是什么 Memcached是一种高性能的分布式内存对象缓存系统.在动态应用,Memcached既能提高访问的速度,同时还减低了数据库的负载.DangaInteractive为提升Li ...
- centos 安装,配置memcached
先查看是否已经安装了memcached输入memcached -h会输出memcached版本,或print phpinfo查看: memcached需要libevent支持,没有libevent,就 ...
- Linux下PHP安装配置MongoDB数据库连接扩展
Web服务器: IP地址:192.168.21.127 PHP安装路径:/usr/local/php 实现目的: 安装PHP的MongoDB数据库扩展,通过PHP程序连接MongoDB数据库 具体操作 ...
- win10配置Memcached及MVC5测试分布式缓存入门
win10配置Memcached: 1.安装包下载 2.解压后有: 3.以管理员省份运行cmd: 4.安装:输入cmd命令: E:/memcached-amd64/memcached.exe -d ...
- 如何在Windows平台下安装配置Memcached
Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga Interactive公司的Brad Fitzpatric为首开发的一 ...
- 为订阅内虚拟机批量安装并配置 Microsoft Anti-Malware 扩展
本文提供了对订阅内的 Windows 经典部署虚拟机和资源管理器部署虚拟机执行批量安装并配置 Microsoft Anti-Malware 扩展的 PowerShell 脚本. 关于安装 Window ...
随机推荐
- TCP连接为什么三次握手四次挥手
前几天面试某电商被问住了,问的很细,我就说了说连接过程,必然凉凉.在csdn上找了一篇很详细的博客.https://blog.csdn.net/hyg0811/article/details/1023 ...
- CentOS7设置阿里镜像教程
阿里镜像官方地址http://mirrors.aliyun.com/ 1.点击官方提供的相应系统的帮助 :2.查看不同版本的系统操作: 为linux系统下载源设置阿里镜像的步骤 : 1. 备份 备份C ...
- php速成_day4
一.微信公众平台概述 1.微信发展史 1)2011年1月21日,腾讯推出微信应用程序.(张小龙) 2)2012年8月20日,腾讯推出微信公众平台功能,同年11月开放第三方接口 3)2013年11月注册 ...
- Java8之深入理解Lambda
lambda表达式实战 从例子引出lambda 传递Runnable创建Thread java8之前 Thread thread=new Thread(new Runnable() { @Overri ...
- 集成通用Mapper
通用Mapper集成 1.引入jar包 <mapper.version>3.0.1</mapper.version><persistence-api.version> ...
- c语言中命令行参数argc,argv[]详解
main(int argc,char *argv[ ]) 1.argc为整数 2.argv为指针的指针(可理解为:char **argv or: char *argv[] or: char argv[ ...
- endnote插入|管理文件|成组
信息检索 Endnote Filter(导入)---library(管理)---style(导出) 本地+网络数据库 点击research 在WOS上: 导入改文献: CNKI 导入PDF时选择PDF ...
- 针对Oracle的一系列操作
一.有关于数据库导出dmp的语句. 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中exp system/manager@TEST file=d ...
- linux安装nginx步骤
转载自:https://blog.csdn.net/t8116189520/article/details/81909574,修改部分内容 本文已收录至博客专栏linux安装各种软件及配置环境教程中 ...
- mac 下webstorm调节字体大小
ctr+shift+A功能可以搜索对应功能. 在弹出框中输入Zoom可以轻松设置. 而且有关zoom的功能全部列出. 真是方便. 搜索到change font size with ctrl + whe ...