Install Memcache in Ubuntu

Source: Internet
Author: User
Tags crc32

Install Memcache in Ubuntu

1. Install the apache, php, and mysql environments in Ubuntu: run the following command to minimize setup and installation, and install other extensions step by step as required. Enter the following command at the command prompt:

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-serversudo apt-get install php5

Ii. Install memcache:

1) install the Memcache Server

sudo apt-get install memcached

After installing the Memcache server, we need to start the service:

memcached -d -m 128 -p 11111 -u root

Here we need to describe the memcached service startup parameters:

-P listening port-l connection IP address, the default value is local-d start to start memcached service-d restart to restart memcached service-d stop | shutdown to disable the running memcached service-d install to install memcached service-d uninstall to uninstall memcached service-u run as (only valid when running as root) -MB maximum memory usage, in MB. By default, an error is returned when 64MB-M memory is used up, instead of deleting the maximum number of concurrent connections in item-c. The default value is 1024-f, and the default value is 1.25-n, key + value + flags are 48-H display help by default

2) install the Memcache Client

sudo apt-get install php5-memcache

After the installation, we need to perform simple configuration in php. ini. Open the/etc/php5/apache2/php. ini file and add the following content at the end:

[Memcache]; a high-performance distributed memory object cache system maintains a unified and huge hash table in the memory. It can be used to store data in various formats, including image, video, file, and database retrieval results .; Whether to transparently transfer data to other servers when an error occurs. Memcache. allow_failover = On; Maximum number of servers allowed to receive and send data, valid only when memcache. allow_failover is enabled. Memcache. max_failover_attempts = 20; data will be transferred according to the block size set by this value. The smaller the value, the more extra network transmission is required .; If you find that the speed cannot be explained is reduced, you can try to increase the value to 32768. Memcache. chunk_size = 8192; default TCP port used to connect to the memcached server. Memcache. default_port = 11111; controls the policy for ing keys to the server. The default value "standard" indicates that the old hash policy of the previous version is used .; Set as "consistent" to allow you to add or delete servers in the connection pool without re-computing the key ing between keys and servers .; Memcache. hash_strategy = "standard"; controls the hash function that maps keys to the server. The default value "crc32" uses the CRC32 algorithm, while "fnv" indicates that the FNV-1a algorithm is used .; FNV-1a than CRC32 speed is slightly lower, but the hash effect is better .; Memcache. hash_function = "crc32 ″

Save php. ini and run sudo/etc/init. d/apache2 restart to restart Apache.

Use Memcache in PHP

 Connect ("localhost", 11111); // connect to the Memcache server $ val = "this is a test. "; $ key = md5 ($ val); $ mem-> set ($ key, $ val, 0,120); // insert a cache, the cache time is 120 s $ k = $ mem-> get ($ key); if ($ k) {// determines whether the specified key echo 'from cache: 'is obtained :'. $ k;} else {echo 'normal'; // here we need to replace it with query database and create cache .}

Memcached installation and startup script

Performance problems of using Memcached in PHP

Install Memcached in Ubuntu and its command explanation

Install and apply Memcached

Use Nginx + Memcached's small image storage solution

Getting started with Memcached

For details about Memcached, click here
Memcached: click here

This article permanently updates the link address:

Related Article

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.