PHP Operation Memcache Example Introduction _php skills

Source: Internet
Author: User
Tags php language memcached mysql query php class redis svn client
b/S: Web programs based on browser and server architecture
C/S: QQ SVN client + server

simple text-based protocols:
Redis
Memcache

difference:
are stored in the data, memcache directly saved to memory, Redis saved to memory, after the shutdown to save to the hard disk, memcache Restart the computer, shutdown service will cause data loss
(1) stored in memory
(2) Restart the computer, restart the service all the data is gone
(3) LRU algorithm, according to the most recently used variables, will not use a long time to remove the variable

how PHP operates Memcache
1,php load Extension php_memcache.dll extension
Serialization of
Deserialization
Memcache can save data: string, numeric, array, object
When we get the objects saved in memcache, we need to provide the definition of this class, otherwise, we are prompted to know which class object
Memcahe and Redis:redis can also save hash, data structure


2,memcached Client Operation
c/S through the Client connection service side
Add Php_memcache.dll, but we don't have permission to modify PHP configuration file
But also want to use memory memcache
You can also use the client action
Through socket technology,
MySQL Query
Sorting in English for queries
Chinese-----Sphinx Chinese search engine
Turn off Memcache extension
Using socket technology to complete the crud operation of PHP to Memcache
DLL encapsulates the function class library, which creates memory space and saves data
So can you write your own functions and DLL encapsulation?
The idea is to convert the library of C language in DLL into PHP language.
Live Lei Feng in the network World, share the PHP class file

If a NOTICE level error occurs, modify the PHP error_reporting + e_all+notice
Memcache Life cycle:
Restarting the memcached and restarting the operating system can cause all data to disappear. In addition, the unused cache is automatically deleted based on the LRU (leastrecently Used) algorithm after the content capacity reaches the specified value.
If set expire to 0, it means never expire until the machine restarts or the service restarts
Bones Beat
Save session data to Memcache
The data for the session is saved in the file by default
But we can change the configuration of PHP and let him save it somewhere else.
1, let Memcache to deal with the session
2,

inch but how to get the session variable is no longer the Name property, but is saved by session_id
session_id
When the browser accesses the server, the server assigns session_id to the browser and then session_id to find the corresponding value
If the sessaion is saved by the object, the tired information will be lost when you get it.
But now there are questions:
What if you don't have permission to modify the PHP configuration?
Ini_set () You can set some configuration of PHP in PHP file
Security issues:

Now anyone can access my memcache.
Way to solve the problem:
Firewall

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.