PHP Cache application: PHPMEMCACHE details

Source: Internet
Author: User
The Memcache function library is in PECL (PHPExtensionCommunityLibrary). It is mainly used to set up a temporary storage area for large-capacity memory data. its function is obvious in distributed mode, otherwise it is not recommended to use it. MemcacheEMC error reported when installing and running on ubuntu

The Memcache function Library is used in the PECL (PHP Extension Community Library) to build a temporary storage area for large-capacity memory data. Its role is evident in distributed systems, otherwise, it is not recommended. When installing and running ubuntu, an error is reported:


/Usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:

Cannot open shared object file: No such file or directory

Follow the methods in libeven, memcached, and libmemcache installation to use:

Sudo ln-s/usr/local/lib/libevent-1.4.so.2/usr/lib/libevent-1.4.so.2

This BUG can be fixed.

Log out of the ";" in/etc/php5/conf. d/memcached. ini, restart apache, and call phpinfo () to display memcached information.


$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 11211) or die ("cocould not connect ");
$ Version = $ memcache-> getVersion ();
Echo "Server's version:". $ version. "\ n ";
?>

  1. $ Memcache = new Memcache;
  2. $ Memcache-> connect ('localhost', 11211) or die ("cocould not connect ");
  3. Print_r ($ memcache-> getStats ());
  4. /**
  5. * Array
  6. *(
  7. * [Pid] = & gt; 8052
  8. * [Uptime] = & gt; 9205
  9. * [Time] = & gt; 1205898428
  10. * [Version] => 1.2.5
  11. * [Pointer_size] => 32
  12. * [Rusage_user] = & gt; 0.008000
  13. * [Rusage_system] = & gt; 0.000000
  14. * [Curr_items] => 1
  15. * [Total_items] => 17
  16. * [Bytes] => 57
  17. * [Curr_connections] => 2
  18. * [Total_connections] => 15
  19. * [Connection_structures] => 3
  20. * [Cmd_get] => 9
  21. * [Cmd_set] => 23
  22. * [Get_hits] => 5
  23. * [Get_misses] => 4
  24. * [Evictions] => 0
  25. * [Bytes_read] = & gt; 671
  26. * [Bytes_written] = & gt; 850
  27. * [Limit_maxbytes] = & gt; 10485760
  28. * [Threads] => 1
  29. *)
  30. */
  31. ?>


01. 02. $ memcache = new Memcache;
03. $ memcache-> connect ('localhost', 11211) or die ("cocould not connect ");
04. $ memcache-> set ('name', 'Leo ', 0, 30 );
05. if (! $ Memcache-> add ('name', 'Susan ', 0, 30 ))
06 .{
07. echo 'Susan is exist ';
08 .};
09. $ memcache-> replace ('name', 'power', 0,300 );
10. echo $ memcache-> get ('name ');
11. $ memcache-> delete ('name', 5 );
12.?>


01. 02. function _ callback_memcache_failure ($ host, $ port ){
03. print "memcache '$ host: $ port 'failed ";
04 .}
05. $ memcache = new Memcache;
06. $ memcache-> addServer ('192. 168.1.116', 192 );
07. $ memcache-> setServerParams ('192. 168.1.116', 192, 1, 15, true,
08.
09. '_ callback_memcache_failure ');
10. echo $ memcache-> getServerStatus ('192. 168.1.116', 192 );
11.?>


01. 02. $ memcache = new Memcache;
03. $ memcache-> connect ('localhost', 11211 );
04. $ memcache-> set ('test _ item', 8 );
05. $ memcache-> increment ('test _ item', 4 );
06. echo $ memcache-> decrement ('test _ item', 7 );
07. // Display 5
08.?>


/Usr/local/bin/memcached-d-m 10-u root-l 127.0.0.1-p 11211-c 256-P

/Tmp/memcached. pid

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.