B/s: web programs based on browser and server architecture
C/s: qq svn client + server
Simple text line-based protocol:
Redis
Memcache
Differences:
All data is stored. memcache is saved directly to the memory, redis is saved to the memory, closed, and saved to the hard disk. memcache restarts the computer and closes the service, causing data loss.
(1) Save in memory
(2) restart the computer and restart the service. All data disappears.
(3) The LRU algorithm deletes unused variables based on recently used variables.
How does PHP operate memcache?
1. php LOAD extension php_memcache.dll Extension
Serialization
Deserialization
Data that can be stored by memcache: String, value, array, and Object
When we get the object stored in memcache, we need to provide the definition of this class. Otherwise, the system prompts that we do not know which class the object is.
Memcahe and redis: redis can also save hash and Data Structure
2. memcached client operation
C/S connect to the server through the client
Add php_memcache.dll, but we have no permission to modify the php configuration file.
But you still want to use the memory memcache
You can also use the client
Using socket technology,
Mysql Query
Sort queries in English
Chinese ----- sphsf-chinese Search Engine
Disable memcache Extension
Use socket technology to complete php CRUD operations on memcache
Dll-encapsulated function class libraries that open up memory space and store data
Can I write the same function as the dll package?
The idea is to convert the C class library developed in dll to the php language.
Leifeng from the Internet shared php files.
If a notice-level error occurs, modify php error_reporting + E_ALL + NOTICE.
Memcache lifecycle:
Restarting memcached and the operating system will cause all data to disappear. In addition, when the content capacity reaches the specified value, the unused cache is automatically deleted based on the LRU (LeastRecently Used) algorithm.
If you set expire to 0, it never expires until the server is restarted or the service is restarted.
What do you mean by sin
Save session data to memcache
Session data is stored in the file by default.
However, we can modify the php configuration so that it can be saved elsewhere.
1. Let memcache handle the session
2,
But how to obtain the session variable is not the name attribute, but saved through session_id
Session_id
When the browser accesses the server, the server assigns session_id to the browser and then finds the corresponding value through session_id
If sessaion saves an object, the tired information is lost.
But there are still problems:
What should I do if I have no permission to modify the php configuration?
Ini_set () You can set some php configurations in the php file.
Security Questions:
Now everyone can access my memcache
Solution:
Firewall