小蚂蚁学memcache笔记-php操作memcache(2)
上篇在学习$mem->set();的时候少写了一个参数,第三个参数,MEMCACHE_COMPRESSED,这个参数的作用在于压缩。
memcache是独立机构,是C/S结构。如果memcache满了,LRU算法删除,把最早没有访问过的拿掉。
memcache的分布式 这里是重点
在第二部中将connect这个方法改成addserver(),在链接池中添加了一个memcache服务器。
例如 :
$mem -> new Memcache();$mem -> addServer('127.0.0.1',11211); //增加链接池$mem -> addServer('127.0.0.1',9999); //增加链接池 $mem -> get($key);
memcached尽管是‘分布式’缓存服务器,但服务器端并没有分布式功能。
各个memcache不会互相通信以便信息共享。每个memcache服务的数据不是同步的。
而且把什么样的数据放入到哪一个memcached是由客户端的mem对象来决定的。
当执行addServer的时候,并不是立即去连接mem服务,而是通过计算,hash后才去决定链接哪一台mem服务,所以当大量加入服务到连接池,不会有多余的开销。
memcache细节的研究
生命周期。从放入开始计时,时间到就自动销毁。memcache被销毁有以下几种情况。一,时间到。二、重启memcache。三,重启服务器。
如何将session放入到memcache中保存
修改php.ini配置文件
session.save_handler=user 它有三个选项 user 表示自定义 files入库保存到文件 memcache保存在内存
修改如下 将session.save_handler 改为 memcache
将 session.save_path=“tcp://127.0.0.1,11211”
2. 重启apache
注意:如果session数据存入memcache,那它一定是以session_id为key值进行添加的。
如果以后做大型门户网站,一定要把session写入到memcache。(强烈建议)
如果无法修改php.ini文件,可以通过函数修改php.ini任何配置。可以把以下两句写到脚本的前端
ini_set("session.sava_handler","memcache");ini_set("session.save_path","tcp://127.0.0.1:9999"); //函数的参数都是以减值对的形式存入
ini_set()功能很强大,可以修改php.ini中的任何值。
safe_mode模式的谈论
他们的最大区别就在于,安全模式一旦打开,对服务器上文件的操作几乎失效。
ini_set()只会在很脚本起作用,不对其他文件起作用。

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

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
