PHP 使用memcached,php使用memcached
PHP 使用memcached,php使用memcached
1.添加扩展包
php_memcache.dll
2.在PHP.INI添加
extension=php_memcache.dll
3.程序
<?<span>php </span><span>//</span><span>创建一个mem对象实例</span> <span>$mem</span>=<span>new</span><span> Memcache; </span><span>if</span>(!<span>$mem</span>->connect("10.18.110.213",11211<span>)){ </span><span>die</span>('连接失败!'<span>); } </span><span>//</span><span>增加 //1.增加一个字串</span><span> /*</span><span> if($mem->set('key1',"beijing",MEMCACHE_COMPRESSED,60)){ echo '添加ok'; }</span><span>*/</span> <span>//</span><span>2.添加数值</span><span> /*</span><span> if($mem->set('key1',100,MEMCACHE_COMPRESSED,60)){ echo '添加ok'; }</span><span>*/</span> <span>//</span><span>3.添加数组 //在添加数组是,根据需要. 希望序列号放入 , //serialize<=>unserialize, 如果根据需要,也可以json_encode <=> json_decode</span> <span>$arr</span>=<span>array</span>("bj",'tj'<span>); </span><span>if</span>(<span>$mem</span>->set('key1',<span>$arr</span>,MEMCACHE_COMPRESSED,<span>time</span>()+31*3600*24<span>)){ </span><span>echo</span> '添加数组ok99111'<span>; } </span><span>//</span><span>4.添加对象</span><span> /*</span><span> class Dog{ public $name; public $age; public function __construct($name,$age){ $this->name=$name; $this->age=$age; } } $dog1=new Dog('小狗',50); if($mem->set('key1',$dog1,MEMCACHE_COMPRESSED,60)){ echo '添加对象ok'; }</span><span>*/</span> <span>//</span><span>5.添加null 布尔值</span><span> /*</span><span> if($mem->set('key1',false,MEMCACHE_COMPRESSED,60)){ echo '添加布尔ok'; }</span><span>*/</span> <span>//</span><span>6. 资源类型放入.</span><span> /*</span><span> $con=mysql_connect("127.0.0.1","root","root"); if(!$con){ die('连接数据库失败'); } var_dump($con); echo "<br/>"; if($mem->set('key1',$con,MEMCACHE_COMPRESSED,60)){ echo '添加资源ok'; }</span><span>*/</span> <span>//</span><span>查询</span> <span>$val</span>=<span>$mem</span>->get('key1'<span>); </span><span>//</span><span>修改 //可以使用replace</span> <span>if</span>(<span>$mem</span>->replace("key11",'hello',MEMCACHE_COMPRESSED,60<span>)){ </span><span>echo</span> 'replace ok'<span>; }</span><span>else</span><span>{ </span><span>echo</span> 'replace no ok'<span>; } </span><span>//</span><span>删除</span> <span>echo</span> "<br/>"<span>; </span><span>if</span>(<span>$mem</span>->delete('key14'<span>)){ </span><span>echo</span> 'key14 删除'<span>; }</span><span>else</span><span>{ </span><span>echo</span> 'key14不存在'<span>; }</span>

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 web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

With the rapid development of the Internet, more and more applications need to face a large number of concurrent requests. How to improve the concurrent processing capabilities of applications has become a problem that developers need to solve. Among them, using Memcache caching technology for concurrency optimization has become a relatively popular solution. Memcache is an efficient caching technology suitable for large-scale web applications, databases and distributed systems. Its characteristic is to store data in memory to achieve high-speed read and write operations. During the data access process of web applications,

How to use Memcache for efficient data writing and querying in PHP development? With the continuous development of Internet applications, the requirements for system performance are getting higher and higher. In PHP development, in order to improve system performance and response speed, we often use various caching technologies. One of the commonly used caching technologies is Memcache. Memcache is a high-performance distributed memory object caching system that can be used to cache database query results, page fragments, session data, etc. By storing data in memory

How to use Memcache to optimize data storage operations in your PHP application? In web application development, data storage is a crucial link. In PHP applications, Memcache, as a memory cache system, can effectively improve the efficiency of data storage and reading operations. This article will introduce how to use Memcache to optimize data storage operations in PHP applications, and attach specific code examples. Step 1: Install the Memcache extension First, you need to install Me in your PHP environment

The practice and thinking of Memcache caching technology to optimize data interaction in PHP In modern Web applications, data interaction is a very important issue. It is not efficient enough and will limit the scalability and performance of Web applications. In order to speed up data interaction, our usual approach is to optimize the design of the database, improve the performance of the hardware and increase the server capacity. However, these methods all have a common limitation: they increase the cost of the system. In recent years, Memcache technology has made progress in solving this problem.

As web applications become increasingly complex, performance has become a critical issue. In many applications, database queries are one of the most time-consuming operations. In order to avoid frequently reading data from the database, a caching system can be used to store frequently read data in memory for quick access. In PHP development, using Memcached for distributed caching is an extremely common practice. In this article we will introduce how to use Memcached for distributed caching. What is Memca

Memcache is an open source, distributed caching technology. It greatly improves the speed of data access by storing data in memory, thus improving the performance and responsiveness of the website. In PHP projects, Memcache caching technology is also widely used and has achieved good results. This article will deeply explore the application and practice of Memcache caching technology in PHP projects. 1. Principles and advantages of Memcache Memcache is a memory caching technology that can store data
