Install and test Memcache in Windows

Source: Internet
Author: User
Tags overview example

You have not installed Memcache in windows before. If you only need a few lines of shell in linux, you can do it. Now baidu, let's take a look at the installation process.

Install Memcache in Windows
1. Download memcache for windows. : Http://jehiah.cz/projects/memcached-win32. we recommend downloading binaries and decompress it (in this example, decompress it to c: memcached ).
2. In the command line status, enter c: memcachedmemcached.exe-d install. So far, memcached has been installed as a windows service.
3. Enter c: memcachedmemcached.exe-d start in the command line to start the memcached service. Of course, you can also choose to start in windows Service
You are not mistaken. It is so simple that the server end of the simple three-step memcache is ready.

Install Memcached module in php
1. Download The php_memcache.dll module. You can find the corresponding version from http://downloads.php.net/pierre,
Php5.3 direct download http://shikii.net/blog/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

2. Modify php. ini and add the following content:

Extension = php_memcache.dll3, restart the apache server, and check phpinfo. If memcache exists, the installation is successful!

Test Memcached in windows
The test code is as follows:

The Code is as follows: Copy code

<? Php
$ Mem = new Memcache;
$ Mem-> connect ("127.0.0.1", 11211 );
$ Mem-> set ('key', 'Hello Memcached! ', 0, 60 );
$ Val = $ mem-> get ('key ');
Echo $ val;
?>

Example #1 memcache extension overview example

In this example, an object is being saved in the cache and then retrieved back. object and other non-scalar types are serialized before saving, so it's impossible to store resources (I. e. connection identifiers and others) in the cache.

The Code is as follows: Copy code

<? Php

$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 11211) or die ("cocould not connect ");

$ Version = $ memcache-> getVersion ();
Echo "Server's version:". $ version. "<br/> n ";

$ Tmp_object = new stdClass;
$ Tmp_object-> str_attr = 'test ';
$ Tmp_object-> int_attr = 123;

$ Memcache-> set ('key', $ tmp_object, false, 10) or die ("Failed to save data at the server ");
Echo "Store data in the cache (data will expire in 10 seconds) <br/> n ";

$ Get_result = $ memcache-> get ('key ');
Echo "Data from the cache: <br/> n ";

Var_dump ($ get_result );

?>


Example #2 Using memcache session handler

The Code is as follows: Copy code

<? Php

$ Session_save_path = "tcp: // $ host: $ port? Persistent = 1 & weight = 2 & timeout = 2 & retry_interval = 10, tcp: // $ host: $ port ";
Ini_set ('session. save_handler ', 'memcache ');
Ini_set ('session. save_path ', $ session_save_path );

?>


-P listening port
-L connected IP address. The default value is local
-D start: start the memcached service.
-D restart: restart the memcached service.
-D stop | shutdown the running memcached Service
-D install the memcached Service
-D uninstall memcached Service
-U runs as the identity (only valid when running as root)
-MB maximum memory usage, in MB. The default value is 64 MB.
-An error is returned when M memory is used up, instead of deleting items.
-C: Maximum number of simultaneous connections. The default value is 1024.
-F block size growth factor, default value: 1.25
-N: minimum allocation space. The default value of key + value + flags is 48.
-H Show Help

Related Article

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.