memcached,memcached Installing _php Tutorials

Source: Internet
Author: User
Tags close close

memcached,memcached Installation


Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read.

Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.

Storage mode:

To improve performance, the data saved in memcached is stored in Memcached's built-in memory storage space. Because the data exists only in memory, restarting the memcached and restarting the operating system will cause all data to disappear. Additionally, when the content capacity reaches the specified value, the unused cache is automatically deleted based on the LRU (Least recently used) algorithm. The memcached itself is a server designed for caching, so there is not too much consideration for permanent data issues.

Tips for use:

Many languages implement a client that connects Memcached, with Perl and PHP as the main.

First, the installation of the Windows environment is described here.

1, download memcache Windows stable version, unzip and put under a disk, such as in c:\memcached

2. Enter ' c:\memcached\memcached.exe-d install ' installation in CMD

3, re-enter: ' c:\memcached\memcached.exe-d start ' start.

Memcached will start automatically every time a service is turned on for Windows. This way the server side is already installed.

4, very simple. But it's not over yet, you just installed a memcached caching server, and you haven't associated with PHP yet. So in the PHP program can not be used.

Since my PHP version is 5.2.17, the downloaded Php_memcache.dll also corresponds. If your PHP is 5.3+, you can download it here

Php_memcache-cvs-20090703-5.3-nts-vc6-x86.zip

Install the same as usual to add extensions, copy the DLL files to your PHP directory's ext directory, and then,

Add Extension=php_memcache.dll to the php.ini, restart the server, and you should see the configuration information in the Phpinfo.

Second, the installation under the CentOS

Installing yum-y Install memcached

Set to boot Chkconfig--level 2345 memcached on

Start and stop/etc/init.d/memcached start|stop

Add: If the installation lacks additional support, you can:

Yum Groupinstall "Development Tools"

Common operations

Memcache::add adds a value that returns false if it already exists

Memcache::addserver Add a server address that is available for use

Memcache::close Close a Memcache object

Memcache::connect Creating a Memcache Object

Memcache::d ebug control Debugging function

Memcache::d ecrement to subtract a value from a saved key

Memcache::d elete Delete a key value

Memcache::flush to clear all cached data

Memcache::get get a key value

Memcache::getextendedstats get run System statistics for all processes in the process pool

Memcache::getserverstatus getting parameters to run the server

Memcache::getstats returns some running statistics for the server

Memcache::getversion returns the version information of the running Memcache

Memcache::increment an addition to the value in a saved key

Memcache: Create a Memcache Persistent connection object:p Connect

Memcache::replace R overwrite an existing key

Memcache::set adds a value that, if already present, overwrite

Memcache::setcompressthreshold compression of data larger than a certain size

Memcache::setserverparams Modifying the server's parameters at run time

 Php//Connection Memcache$mem=NewMemcache; $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. "
"; //Saving Array Data$arr=Array(' AAA ', ' BBB ', ' CCC ', ' DDD ')); $mem->set (' Key2 ',$arr, 0, 60); $val 2=$mem->get (' Key2 '); Echo"Get Key2 Value:"; Print_r($val 2); Echo"
"; //Delete Data$mem->delete (' Key1 '); $val=$mem->get (' Key1 '); Echo"Get Key1 Value:".$val. "
"; //Clear All data$mem-Flush(); $val 2=$mem->get (' Key2 '); Echo"Get Key2 Value:"; Print_r($val 2); Echo"
"; //Close Connection$mem-Close (); ?>

How the Memcached works:

First of all, memcached is running on one or more servers in the daemon mode, accepting the client's connection operation at any time, the client can be written in various languages, the currently known client API includes perl/php/python/ruby/java/c#/c and so on.

PHP and other clients after establishing a connection with the Memcached service, the next thing is to access the object, each access to the object has a unique identifier key, access operations are through this key, the object saved to memcached is actually placed in memory, is not saved in the cache file, which is why memcached can be so efficient and fast. Note that these objects are not persistent and the data inside is lost after the service is stopped.

Memcachedb:

Memcachedb is a distributed, key-value form of persistent storage system. It is not a cache component, but a reliable, fast, persistent storage engine based on object access. The protocol is consistent with memcache (incomplete), so many memcached clients can connect to it. Memcachedb uses Berkeley DB as a durable storage component, so many of Berkeley DB's features are supported.

We are standing on the shoulders of giants. Memcachedb's front-end cache is memcached

Front end: memcached's network layer

Back-end: BerkeleyDB Storage

What is the relationship and difference between memcached and smarty?

Memcache is a high-performance distributed memory object caching system that logs the cache to a memory system.

For example, getting a list display from a database, but not trying to read the database every time, requires caching, and memcache is one of those things that keeps records in memory Use

For example, to re-db get data display, DB--Memcache client

First Judge Memcache have no data, if not read the DB, and then the DB obtained records saved in Memcache

The next time you need to read the record, you can read it directly in the memcache, so that you can share the burden of the database and much faster.

Smarty is a template engine written in PHP that is designed to separate the PHP programmer from the front-end staff, so that programmers change the logic content of the program without affecting the front-end staff's page design.

The Smarty is run in the view of the MVC structure.

For example PHP we want to display a variable, it is necessary to write the Echo $a;

The use of smarty is required to write {$a}, after compiling, will automatically display the Echo $a; Smarty in the cache, PHP to run, before you can output to the browser, PHP run generated HTML output is required to operate, and Smarty will be the previously run PHP generated HTML saved. If you call this PHP again, the previous HTML will be printed directly. Plays the role of caching.

Memcache and Smarty have no relationship, the two roles are not the same, there is no connection.

http://www.bkjia.com/PHPjc/993268.html www.bkjia.com true http://www.bkjia.com/PHPjc/993268.html techarticle memcached,memcached Installation Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It caches data and objects in memory ...

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