Application of caching server under Linux

Source: Internet
Author: User
Tags config key memcached connect requires zts linux
Absrtact: Because the data stored by the database is more and more large, the query speed becomes more and more slow, so there is a need for Linux caching server application, this article introduces the installation of memcached and simple use.

This article only introduces Memcached's PHP API and wants to see other API files on memcached, please visit


I. Environmental requirements

Second, download the relevant software

III. Installation and Configuration

1. Installation memcached

2. Install memcache PHP Module

3. Test scripts

Four, about this article




I. Environmental requirements

Installation memcached requires Libevent library support, so check to see if Libevent is installed before installing memcached. The test environment also requires PHP support, this article assumes that PHP has been installed into the/usr/local/php directory, that is, when compiling PHP using the Perfix parameter to specify the directory (--prefix=/usr/local/php)

Second, download the relevant software

memcached Download Address:

memcache PHP module Download address: Http:// recommended to use version 1.5

Libevent Download Address:

This article no longer describes how to install Libevent

III. Installation and Configuration

1. Installation memcached

root@tonyvicky:# Tar vxzf memcached-1.1.12.tar.gz

root@tonyvicky:# CD memcached-1.1.12

root@tonyvicky:#. /configure--prefix=/usr/local/memcached

root@tonyvicky:# make

root@tonyvicky:# make Install

To start the service after the installation is complete

root@tonyvicky:# Cd/usr/local/memcached/bin

root@tonyvicky:#. /memcached-d-M 50-p 11211-u Root

Parameter Description-m specifies the number of megabytes of cache space to use;-p specifies the port to listen to, and-u specifies which user to run

2. Install memcache PHP Module

root@tonyvicky:# Tar vxzf memcache-1.5.tgz

root@tonyvicky:# CD memcache-1.5


root@tonyvicky:#. /configure--enable-memcache--with-php-config=/usr/local/php/bin/php-config--with-zlib-dir

root@tonyvicky:# make

root@tonyvicky:# make Install

After installation, there will be a hint like this:

Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/

Keep this in mind, then modify the php.ini, and put

Extension_dir = ". /”

Amended to

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"

and add a row

3. Test scripts

Write a PHP program to test yourself.

《? Php

$memcache = new Memcache; Create a Memcache object

$memcache-"Connect" (' localhost ', 11211) or die ("could not Connect"); Connecting memcached servers

$memcache-"Set" (' Key ', ' test '); Set a variable to memory, the name is the key value is test

$get _value = $memcache-"Get" (' key '); To remove the value of a key from memory

echo $get _value;

? 》

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