Install and use Memcached in w7

Source: Internet
Author: User
: 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.

  1. // Connect to Memcache
  2. $ Mem = new Memcache;
  3. $ Mem-> connect ("localhost", 11211 );
  4. // Save data
  5. $ Mem-> set ('key1', 'This is first value', 0, 60 );
  6. $ Val = $ mem-> get ('key1 ');
  7. Echo "Get key1 value:". $ val ."
    ";
  8. // Replace data
  9. $ Mem-> replace ('key1', 'This is replace value', 0, 60 );
  10. $ Val = $ mem-> get ('key1 ');
  11. Echo "Get key1 value:". $ val ."
    ";
  12. // Save the array data
  13. $ Arr = array ('AAA', 'BBB ', 'CCC', 'ddd ');
  14. $ Mem-> set ('key2', $ arr, 0, 60 );
  15. $ Val2 = $ mem-> get ('key2 ');
  16. Echo "Get key2 value :";
  17. Print_r ($ val2 );
  18. Echo"
    ";
  19. // Delete data
  20. $ Mem-> delete ('key1 ');
  21. $ Val = $ mem-> get ('key1 ');
  22. Echo "Get key1 value:". $ val ."
    ";
  23. // Clear all data
  24. $ Mem-> flush ();
  25. $ Val2 = $ mem-> get ('key2 ');
  26. Echo "Get key2 value :";
  27. Print_r ($ val2 );
  28. Echo"
    ";
  29. // Close the connection
  30. $ Mem-> close ();
  31. ?>
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?

  1. // Connect to Memcache
  2. $ Mem = new Memcache;
  3. $ Mem-> addServer ("localhost", 11211 );
  4. $ Mem-> addServer ("localhost", 11212 );
  5. // Save data
  6. $ Mem-> set ('key1', 'This is first value', 0, 60 );
  7. $ Val = $ mem-> get ('key1 ');
  8. Echo "Get key1 value:". $ val ."
    ";
  9. // Save the array data
  10. $ Arr = array ('AAA', 'BBB ', 'CCC', 'ddd ');
  11. $ Mem-> set ('key2', $ arr, 0, 60 );
  12. $ Val2 = $ mem-> get ('key2 ');
  13. Echo "Get key2 value :";
  14. Print_r ($ val2 );
  15. Echo"
    ";
  16. // Delete data
  17. $ Mem-> delete ('key1 ');
  18. $ Val = $ mem-> get ('key1 ');
  19. Echo "Get key1 value:". $ val ."
    ";
  20. // Close the connection
  21. $ Mem-> close ();
  22. ?>


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.

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.