Simple use of memcache in PHP

Source: Internet
Author: User
: This article mainly introduces the simple use of memcache in PHP. if you are interested in the PHP Tutorial, refer to it. Record it. if your head will not work well in the future, you can go back and have a look.

1. download memcached first. There are many memcached files on Baidu.

2. decompress the package to any local location and remember the location. here I decompress it to the memcached folder on disk D.

3. open the terminal, that is, the dos console (press win + r under windows, enter cmd, and press enter). at this time, a familiar dos interface is displayed. First, go to the disk where you want to remember it (I decompress it on D: \ memcached, so I enter "D:" and press enter to check whether there is a corresponding folder in dir)

We can see that there is this folder, so we started to install it.

4. enter this folder ("cd memcached"), enter "memcached.exe-d install", and press Enter. After a pause, the installation is complete ,.


5. to start the memcache service now, enter "memcached.exe-d start" and press Enter. It will also start after a pause.

6. check whether the service is started, press win + r, and enter "services. msc ", and then you will enter the service window. Find out if you have seen the memcached service. this is self-starting at boot.


The installation has come to an end, and you need to start using it now.

1. the memcached client has been installed, but we still cannot operate on PHP. Therefore, we need to add memcache extensions to PHP. (memcached drivers are divided into memcached and memcache extensions, I used phpStudy's integrated development environment, which has various built-in drivers. wamp server can be used for searching and downloading on the Internet, put it in the ext folder under the PHP directory and go to php. add "extension = memcache. dll ", restart" apache ". Print "phpinfo ()" and check if you have seen memcache.


2. then you can use it. as mentioned above, there are two extensions. you can find them in the php manual based on your own extensions. don't use them wrong.


3. paste a demo of mine.

Demo1.php

 Connect ('localhost') or die ("error"); // the default port connecting to memcache is 11211. do not write $ memcache-> set ('key', '123 ', MEMCACHE_COMPRESSED, 10); // The Expiration Time set here is 10 seconds.

Demo2.php

 Connect ('localhost') or die ("error"); echo"
";var_dump($memcache->get('key'));

Through demo1.php settings, demo2.php can also be accessed. is it successful !, There are many examples on the internet. here we will not repeat them one by one. Also, when we connect to the memcache service, there will be a number 11211 next to it, which is the default listening port of memcache.

Happy new year!



The above introduces the simple use of memcache in PHP, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.