Ant Financial memcache notes-php operations on memcache (2) I wrote less than one parameter when learning $ mem-> set (); and the third parameter, MEMCACHE_COMPRESSED, this parameter is used for compression.
Memcache is an independent organization and is a C/S structure. If memcache is full, the LRU algorithm is deleted to remove the oldest unaccessed memcache.
Distributed memcache is the focus here
In the second part, change the connect method to addserver () and add a memcache server to the connection pool.
For example:
$ Mem-> new Memcache (); $ mem-> addServer ('2017. 0.0.1 ', 11211); // adds the link pool $ mem-> addServer ('2017. 0.0.1 ', 9999); // adds the link pool $ mem-> get ($ key );
Although memcached is a 'distributed 'cache server, the server does not have distributed functions.
Each memcache does not communicate with each other for information sharing. Data of each memcache service is not synchronized.
What kind of data to which memcached is put is determined by the mem object of the client.
When addServer is executed, it does not connect to the mem service immediately, but is computed and hashed before deciding which mem service to connect to. Therefore, when a large number of services are added to the connection pool, there will be no additional overhead.
Memcache details
Lifecycle. From time to time, the time is automatically destroyed. Memcache is destroyed in the following situations. 1. time is up. 2. restart memcache. 3. restart the server.
How to store sessions in memcache
Modify the php. ini configuration file
Session. save_handler = user it has three options: user, which indicates that custom files are stored in the database and saved to the file memcache.
Modify session. save_handler to memcache.
Set session. save_path = "tcp: // 127.0.0.1, 11211"
2. restart apache
Note: If session data is stored in memcache, it must be added with the session_id as the key value.
If you want to create a large portal website in the future, you must write the session into memcache. (Strongly recommended)
If you cannot modify the php. ini file, you can use the function to modify any configuration of php. ini. You can write the following two statements to the front-end of the script:
Ini_set ("session. sava_handler "," memcache "); ini_set (" session. save_path "," tcp: // 127.0.0.1: 9999 "); // Function parameters are saved as impairment pairs.
Ini_set () is very powerful and can modify any value in php. ini.
Safe_mode mode
The biggest difference between them is that once the security mode is opened, the operations on files on the server almost fail.
Ini_set () only works in scripts and does not work in other files.