首页 / PHP / php配置memcached的扩展。
php配置memcached的扩展。
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php配置memcached的扩展。,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4084字,纯文字阅读大概需要6分钟。
内容图文
![php配置memcached的扩展。](/upload/InfoBanner/zyjiaocheng/1305/defd112f896740a9a6066d6358db50d5.jpg)
(一)安装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的基本 命令<SPAN style=‘font-family: "Times New Roman";‘>( 安装、卸载、启动、配置相关<SPAN style=‘font-family: "Times New Roman";‘>)
:-p 监听的端口
-l 连接的<SPAN style=‘font-family: "Times New Roman";‘>IP 地址 "Times New Roman";‘>, 默认是本机
-d start 启动<SPAN style=‘font-family: "Times New Roman";‘>memcached服务
-d restart 重起<SPAN style=‘font-family: "Times New Roman";‘>memcached服务
-d stop|shutdown 关闭正在运行的<SPAN style=‘font-family: "Times New Roman";‘>memcached服务
-d install 安装<SPAN style=‘font-family: "Times New Roman";‘>memcached服务
-d uninstall 卸载<SPAN style=‘font-family: "Times New Roman";‘>memcached服务
-u 以的身份运行 <SPAN style=‘font-family: "Times New Roman";‘>(仅在以"Times New Roman";‘>root运行的时候有效"Times New Roman";‘>)
-m 最大内存使用,单位<SPAN style=‘font-family: "Times New Roman";‘>MB。默认"Times New Roman";‘>64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是<SPAN style=‘font-family: "Times New Roman";‘>1024
-f 块大小增长因子,默认是<SPAN style=‘font-family: "Times New Roman";‘>1.25
-n 最小分配空间,<SPAN style=‘font-family: "Times New Roman";‘>key+value+flags默认是<SPAN
style=‘font-family: "Times New Roman";‘>48
-h 显示帮助
memcached的基本命令<SPAN style=‘font-family: "Times New Roman";‘>(当<SPAN style=‘font-family: "Times New Roman";‘>memcached 启动后 用于对<SPAN style=‘font-family: "Times New Roman";‘>memcached管理的数据和本身运行状态相关的命令<SPAN style=‘font-family: "Times New Roman";‘>):
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("内存中无此数据需要查询数据库!");
}?>
原文:http://www.cnblogs.com/legend-song/p/3673462.html
内容总结
以上是互联网集市为您收集整理的php配置memcached的扩展。全部内容,希望文章能够帮你解决php配置memcached的扩展。所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。