: This article describes how to install and use Memcached in w7. For more information about PHP tutorials, see.
1. extract the first package and put it under a certain disk, for example, in c: \ memcached.
2. enter 'C: \ memcached \ memcached.exe-d install' on the terminal (that is, the cmd command interface) for installation.
3. enter 'C: \ memcached \ memcached.exe-d start' to start. (Note: In the future, memcached will be automatically started every time it is started on windows. In this way, the server has been installed ).
4. download the php_memcache.dll file and put it in the ext Directory of the php folder.
5. add a reference extension line in php. ini. the code is as follows:
Extension = php_memcache.dll
6. add the following in the php. ini file:
[Memcache]memcache.allow_failover = 1memcache.max_failover_attempts=20memcache.chunk_size =8192memcache.default_port = 11211
It is best to put it under "extension = php_memcache.dll" just now. (This is the default configuration)
7. restart Apache and check phpinfo. if memcache instructions are available, the installation is successful!
If the php configuration is not found after the restart, the octal dll file does not match the installed mamcache version.
-
- // Connect to Memcache
- $ Mem = new Memcache;
- $ Mem-> connect ("localhost", 11211 );
- // Save data
- $ Mem-> set ('key1', 'This is first value', 0, 60 );
- $ Val = $ mem-> get ('key1 ');
- Echo "Get key1 value:". $ val ."
";
- // Replace data
- $ Mem-> replace ('key1', 'This is replace value', 0, 60 );
- $ Val = $ mem-> get ('key1 ');
- Echo "Get key1 value:". $ val ."
";
- // Save the array data
- $ Arr = array ('AAA', 'BBB ', 'CCC', 'ddd ');
- $ Mem-> set ('key2', $ arr, 0, 60 );
- $ Val2 = $ mem-> get ('key2 ');
- Echo "Get key2 value :";
- Print_r ($ val2 );
- Echo"
";
- // Delete data
- $ Mem-> delete ('key1 ');
- $ Val = $ mem-> get ('key1 ');
- Echo "Get key1 value:". $ val ."
";
- // Clear all data
- $ Mem-> flush ();
- $ Val2 = $ mem-> get ('key2 ');
- Echo "Get key2 value :";
- Print_r ($ val2 );
- Echo"
";
- // Close the connection
- $ Mem-> close ();
- ?>
Enable one or more processes on one or more machines.
Use two processes and two ports:
#./Memcached-d-u nobody-m 512 127.0.0.1-p 11211
#./Memcached-d-u nobody-m 512 127.0.0.1-p 11212
Source code printing?
-
- // Connect to Memcache
- $ Mem = new Memcache;
- $ Mem-> addServer ("localhost", 11211 );
- $ Mem-> addServer ("localhost", 11212 );
- // Save data
- $ Mem-> set ('key1', 'This is first value', 0, 60 );
- $ Val = $ mem-> get ('key1 ');
- Echo "Get key1 value:". $ val ."
";
- // Save the array data
- $ Arr = array ('AAA', 'BBB ', 'CCC', 'ddd ');
- $ Mem-> set ('key2', $ arr, 0, 60 );
- $ Val2 = $ mem-> get ('key2 ');
- Echo "Get key2 value :";
- Print_r ($ val2 );
- Echo"
";
- // Delete data
- $ Mem-> delete ('key1 ');
- $ Val = $ mem-> get ('key1 ');
- Echo "Get key1 value:". $ val ."
";
- // Close the connection
- $ Mem-> close ();
- ?>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how to install and use Memcached in w7, including some content. if you are interested in the PHP Tutorial.