How to configure Memcache in Drupal7 _ PHP Tutorial

Source: Internet
Author: User
Tags drupal
Detailed description of how to configure Memcache in Drupal7. This article describes how to configure Memcache in Drupal7. I hope this method will be helpful to you. The configuration of Memcache is not much said. drupal will give you a detailed description of how to configure Memcache in Drupal7 in this article. I hope this method will be helpful to you.

Memcache configuration is not much said. because drupal has many modules and frequent database calls, memcache is a required configuration in the drupal site. This article describes the configuration of memcache in Drupal7, for your convenience.

1. install the memcache service and start memcached.

2. install the drupal memcache module. Http://drupal.org/project/memcache)

3. configure settings. php

The code is as follows:
$ Conf ['cache _ backends '] [] = 'sites/all/modules/memcache. inc ';
// The 'cache _ form' bin must be assigned no non-volatile storage.
$ Conf ['cache _ class_cache_form '] = 'drupaldatabasecache ';
$ Conf ['cache _ default_class '] = 'memcachedrupal ';
$ Conf ['memcache _ key_prefix'] = 'something _ unique ';

Note that memcache is required. the file path of inc is correctly written. as mentioned in the Drupal module directory organization summary, we generally place the memcache module under the contrib folder, therefore, the path may be sites/all/modules/contrib/memcache. inc.
In addition, it is best to set memcache_key_prefix.

4. multiple memcachd services.
By default, if memcache_servers and memcache_bins are not configured, Drupal considers that there is only one server, that is, 127.0.0.1: 11211. if there are multiple memcache instances, add the following configuration.

The code is as follows:
$ Conf ['memcache _ servers'] = array (
'10. 1.1.1: 11211 '=> 'default ',
'10. 1.1.1: 11212 '=> 'default ',
'10. 1.1.2: 11211 '=> 'default ',
'10. 1.1.3: 11211 '=> 'cluster2 ',
'10. 1.1.4: 11211 '=> 'cluster2'
);
$ Conf ['memcache _ bins'] = array (
'Cache' => 'default ',
'Cache _ filter' => 'cluster2 ',
'Cache _ menu '=> 'cluster2'
);

Everything is ready.

Finally, I will explain how to configure multiple memcache instances on a single machine, that is, to build a memcache cluster on a single machine.
We need to modify two files, one is the startup script/etc/init. d/memcached-multi, and the other is the configuration file/etc/sysconfig/memcached.

The code is as follows:
/Etc/sysconfig/memcached

Is used to configure the size of multiple memcache instances

The code is as follows:
PORT = "11211"
USER = "memcached"
MAXCONN = "1024"
CACHESIZE = "512"
OPTIONS = ""
MULTIBUCKET = "2"
CACHESIZEARRAY [1] = "1024"
CACHESIZEARRAY [2] = "128"/etc/init. d/memcached-multi

Is used to start the memcache cluster. (Start, stop, restart)

The code is as follows:
#! /Bin/sh
#
# Chkconfig:-55 45
# Description: The memcached daemon is a network memory cache service.
# Processname: memcached
# Config:/etc/sysconfig/memcached
# Pidfile:/var/run/memcached. pid

# Standard LSB functions
#./Lib/lsb/init-functions

# Source function library.
./Etc/init. d/functions

PORT = 11211
USER = memcached
MAXCONN = 1024
CACHESIZE = 64
OPTIONS = ""
MULTIBUCKET = ""

If [-f/etc/sysconfig/memcached]; then
./Etc/sysconfig/memcached
Fi

[-Z "$ MULTIBUCKET"] & amp; MULTIBUCKET = 1

# Check that networking is up.
./Etc/sysconfig/network

If ["$ NETWORKING" = "no"]
Then
Exit 0
Fi

RETVAL = 0
Prog = "memcached"

Start (){
Echo-n $ "Starting $ prog :"
# Insure that/var/run/memcached has proper permissions
If ["'stat-c % U/var/run/memcached "'! = "$ USER"]; then
Chown $ USER/var/run/memcached
Fi

For I in '/usr/bin/seq 1 $ multibucket'; do
THISCACHESIZE = $ CACHESIZE
[$ {# CACHESIZEARRAY [*]}-gt 0-a $ {CACHESIZEARRAY [$ I]: -0}-gt 0] & THISCACHESIZE =$ {CACHESIZEARRAY [$ I]}
Daemon -- pidfile/var/run/memcached. pid memcached-d-p $ PORT-u $ USER-m $ THISCACHESIZE-c $ MAXCONN-P/var/run/memcached-$ I. pid $ OPTIONS
Let RETVAL = $ RETVAL + $?
Let PORT = $ PORT + 1
Done
Echo
[$ RETVAL-eq 0] & touch/var/lock/subsys/memcached
}
Stop (){
Echo-n $ "Stopping $ prog :"
For I in '/usr/bin/seq 1 $ multibucket'; do
Killproc-p/var/run/memcached-$ I. pid/usr/bin/memcached
Let RETVAL = $ RETVAL + $?
Done
Echo
If [$ RETVAL-eq 0]; then
Rm-f/var/lock/subsys/memcached
Rm-f/var/run/memcached. pid
Fi
}

Restart (){
Stop
Start
}

# See how we were called.
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Status)
Echo "Warning: This status check is laughable. Inspect netstat or ps output manually ."
Status memcached
;;
Restart | reload | force-reload)
Restart
;;
Condrestart)
[-F/var/lock/subsys/memcached] & restart |:
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | reload | force-reload | condrestart }"
Exit 1
Esac

Exit $ RETVAL

So far, some are ready.

Bytes. The configuration of Memcache is not much said, because of the module...

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.