php中内存缓存memcached实例
Memcached是高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。 Memcached由Danga Interactive开发,用于提升LiveJournal.com访问速度的。LJ每秒动态页面访问量几千次,用户700万。Memcached将数据库负载大幅度降低,更好的分配资源,更快速访问。
php教程中内存缓存memcached实例
windows下的memcache安装:
1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:memcached
2. 在终端(也即cmd命令界面)下输入 ‘c:memcachedmemcached.exe -d install
’ 安装
3. 再输入: ‘c:memcachedmemcached.exe -d start’ 启动。note: 以后
memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完
毕了。
4.下载http://cmy2009.ihost.tw/download,(php_memcache地址)请自己查找对应的
php版本的文件
5. 在c:winntphp.ini 加入一行 ‘extension=php_memcache.dll’
6.重新启动apache,然后查看一下phpinfo,如果有memcache,那么就说明安装成功!
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 显示帮助
memcache环境测试:
运行下面的php文件,如果有输出,就表示环境搭建成功。开始领略memcache的魅力把
!
$memcache = memcache_connect('localhost', 11211);
if ($memcache) {
$memcache->set("str_key", "string to store in memcached");
$memcache->set("num_key", 123);$object = new stdclass;
$object->attribute = 'test';
$memcache->set("obj_key", $object);$array = array('assoc'=>123, 345, 567);
$memcache->set("arr_key", $array);var_dump($memcache->get('str_key'));
var_dump($memcache->get('num_key'));
var_dump($memcache->get('obj_key'));
}
else {
echo "connection to memcached failed";
}
?>
memcached是高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库教程负载,提升访问速度。
memcached由danga interactive开发,用于提升livejournal.com访问速度的。lj每秒动态页面访问量几千次,用户700万。memcached将数据库负载大幅度降低,更好的分配资源,更快速访问。
为什么不使用数据库做这些?
暂且不考虑使用什么样的数据库(ms-sql, oracle, postgres, mysql教程-innodb, etc..), 实现事务(acid,atomicity, consistency, isolation, and durability )需要大量开销,特别当使用到硬盘的时候,这就意味着查询可能会阻塞。当使用不包含事务的数据库(例如mysql-myisam ),上面的开销不存在,但读线程又可能会被写线程阻塞。
memcached从不阻塞,速度非常快。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools
