PHP in-memory cache memcached Instance _php tutorial

Source: Internet
Author: User
Tags mysql tutorial
Memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications. Memcached is developed by Danga Interactive to increase the speed of livejournal.com access. LJ Dynamic page visits thousands of times per second, user 7 million. Memcached significantly reduces database load, better allocation of resources, faster access.

PHP tutorials in memory cache memcached instances


Memcache installation under Windows:
1. Download Memcache's Windows stable version and unzip it under a disk, for example, in c:memcached
2. Enter ' c:memcachedmemcached.exe-d install ' in terminal (also cmd command interface)

' Installation
3. Re-enter: ' c:memcachedmemcached.exe-d start ' starts. Note: Later

Memcached will start automatically every time a service is powered on for Windows. So the server side is already installed

Finished.
4. Download Http://cmy2009.ihost.tw/download, (Php_memcache address) please find the corresponding

PHP Versions of files
5. Add a line of ' Extension=php_memcache.dll ' to C:winntphp.ini
6. Restart Apache, then check the phpinfo, if there is memcache, then the installation is successful!

Basic Settings for memcached:

-P Listening Port
-L connected IP address, default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown Close the running memcached service
-D Install memcached service
-d Uninstall Uninstall memcached service
-U Run as (only valid when running as root)
-m maximum memory usage, in megabytes. Default 64MB
-M memory is exhausted when an error is returned instead of deleting an item
-c Maximum number of simultaneous connections, default is 1024
-F Block size growth factor, default is 1.25
-N Minimum allocated space, key+value+flags default is 48
-H Display Help

Memcache Environmental Testing:
Running the following PHP file, if there is output, indicates that the environment was built successfully. Begin to appreciate the charm of memcache

$memcache = Memcache_connect (' localhost ', 11211);

if ($memcache) {
$memcache->set ("Str_key", "string to store in memcached");
$memcache->set ("Num_key", 123);

$object = new Stdclass;
$object->attribute = ' Test ';
$memcache->set ("Obj_key", $object);

$array = Array (' Assoc ' =>123, 345, 567);
$memcache->set ("Arr_key", $array);

Var_dump ($memcache->get (' Str_key '));
Var_dump ($memcache->get (' Num_key '));
Var_dump ($memcache->get (' Obj_key '));
}
else {
echo "Connection to memcached failed";
}
?>

Memcached is a high-performance, distributed memory object caching system that reduces database tutorial load and increases access speed in dynamic applications.
Memcached is developed by Danga Interactive to increase the speed of livejournal.com access. LJ Dynamic page visits thousands of times per second, user 7 million. Memcached significantly reduces database load, better allocation of resources, faster access.


Why not use a database to do this?

For the moment, do not consider what database (Ms-sql, Oracle, Postgres, MySQL tutorial-innodb, etc), implement transactions (acid,atomicity, consistency, isolation, and Durability) requires a lot of overhead, especially when used on a hard disk, which means that queries can be blocked. When using a database that does not contain transactions (for example, Mysql-myisam), the overhead does not exist, but the read thread may be blocked by the write thread.
Memcached never block, very fast.

http://www.bkjia.com/PHPjc/630846.html www.bkjia.com true http://www.bkjia.com/PHPjc/630846.html techarticle memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications. Memcached developed by Danga Interactive for the promotion of ...

  • 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.