PHP中memcached的介绍和工作原理
memcached介绍
一、概念
1、memcached
来自wiki:memcache是这个项目的名称,memcached是它服务器端主程序的文件名。
memcache是danga.com的一个项目,最早为liveJournal服务,目前很多人利用这个缓存项目来构建自己的大负载网站,来分担数据库的压力。它的工作机制是在内存中开辟一块空间,然后建立一个hash table,memcached主程序自己管理这个hash table
二、工作原理
memcached以守护程序的方式运行于一个或多个服务器中,随时接受多个客户端的连接操作,客户端可以由各种语言编写,目前已知客户端API包括Perl/php/python/ruby/java/c#/c等等。客户端在与memcached服务建立连接以后,接下来就是存取对象,每个被存取的对象有一个唯一的key,保存到memcached中的对象是放在内存中的,而不是保存在cache文件中。
它采用C/S模式,在server端启动服务进程,指定监听的IP,自己的端口号,使用的内存大小。目前版本主程序是通过C语言实现
三、如何在PHP中使用
1、安装PHP的memcache扩展,安装完毕后通过phpinfo()可以查看该扩展配置信息,可以在php.ini中更改这些配置信息。
2、测试代码:
Copy to Clipboard引用的内容:[www.bkjia.com] $memcache = new Memcache;$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)\n";
$get_result = $memcache->get('key');
echo "Data from the cache:\n";
var_dump($get_result);
?>
以上所有函数的参考均可在PHP手册中查到

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
