if you has error bug and not edit content.
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7562 of /home/content/b/1/9/b19842723/html/2012/includes/common.inc).
--------solved---------
Intalled: http://drupal.org/project/taxonomy_orphanage
Ran it through the admin pages and it solved my troubles.
Drupal article
Monday, July 28, 2014
Monday, May 19, 2014
Install Percona Server 5.6
Install Percona Server 5.6
warning: /home/centos/Downloads/Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
error: Failed dependencies:
Percona-Server-client-56 is needed by Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64
Percona-Server-shared-56 is needed by Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64
rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
yum install Percona-Server-server-56 Percona-Server-client-56 Percona-Server-shared-56
/etc/init.d/mysql start
There you have it, a freshly installed Percona Server 5.6.17 on CentOS 6.5 Linux container. Yay!
Wednesday, March 26, 2014
Essential Drupal development tools
You can build Drupal websites with just a few tools, such as a code editor, browser and dev environment. While it is not necessary to use additional tools, tools do make your life easier and can save you a tonne of time and improve the quality of your work. So let’s take a look at the essential tools to use to develop with Drupal.
Drush
Drush is one of the most popular, if not the most popular, Drupal development tool out there. Drush is the command line and scripting interface for Drupal. You can use it to speed up installing, developing and maintaining Drupal sites. It takes some getting used to, and there are a lot of commands to remember but, once you do, it is a real time saver. Rather than clicking through the admin interface to achieve something, you simply type in one command. When building Drupal sites and developing custom modules and themes, this can really help.
Get Drush
The developers behind Drush recently moved its code repository from drupal.org to Github, where you can download or clone it. There are a few ways to install it, the drupal.org installation documentation is the best place to start.
Devel
Devel is probably the single most important tool for module development, behind Drush. Devel has sub-modules, such as Devel Generate and Theme Developer, built in for extra power and functionality.
Devel does a lot of useful things, such as:
- Inspect PHP arrays and objects with Devel tools like dpm(). This alone is vital when developing modules.
- Print database queries for each page load, making it easier for you to identity slow queries
- Generate dummy content, taxonomy terms and users with Devel Generate
- Theme Developer displays important information about themes which can be a real time saver for theme development
- Information on node access for nodes (are nodes protected or visible to the public)
Some of these are provided by Devel itself, and some by one of the sub-modules that comes with the Devel package.
Devel should only be used for development and never left enabled on a live website. It is best to not even deploy it to the live site.
Devel uses Krumo when inspecting arrays and objects with Devel. Krumo is an alternative to print_r and var_dump and displays human readable structured information about a PHP variable. Once installed, when you run Devel’s dpm() function, Krumo will handle the output in the browser and make it easier for you to see the particular variable and drill into.
Get Devel
You can get from the Devel project page. It is currently available for both Drupal 6 and Drupal 7.
Examples module
The Examples module is a useful collection of example code for common code implementations. It comes with sub-modules such as ajax_example, email_example, node_example and batch_example. If you are stuck on how to write code to achieve a particular task, the Examples module might just provide the inspiration that you need.
Get Examples
You can get it from the Examples project page. It is currently available for Drupal 6, Drupal 7 and Drupal 8.
Coder
The Coder module ensures that your code adheres to the Drupal coding standards.
Coder includes two submodules: Coder Review and Coder Upgrade. Coder Review allows you to verify that a module meets the Drupal coding standards and lets you know if you need to change something if the Drupal API changes. Coder Upgrade helps you upgrade your modules or themes to a new version of Drupal. It will actually rewrite parts of your code for you.
Coder now includes Drupal Coder Sniffer (was at https://drupal.org/project/drupalcs). Coder Sniffer uses PEAR’s PHP Codesniffer and applies it to the Drupal coding standard. When you run it against a piece of code, it will tell you which parts of the code do not adhere to the standard (if any). You can run it in the admin interface, or command line.
Get Coder
You can get it from the Coder project page. It is currently available for both Drupal 6 and Drupal 7.
Security Review
The Security Review runs tests against your site to identify security problems and provides a report of these problems. It doesn’t magically fix security issues for you - after it identifies the potential issues, you need to go through and remedy them - but it does save time.
Get Security Review
You can get it from the Security Review project page. It is currently available for both Drupal 6 and Drupal 7.
Features
Turn configuration into a module so that you can deploy it and source control it. This is essential up to and including Drupal 7 because without it, a lot of the changes required to meet a certain use-case will be stored in the database only. You should not really make those changes on the live site but if you make them on your local version, how do you deploy them to live? Features makes this possible. This is incredibly helpful even if you are a single developer working on a single site. It is vital if you are working with more than one developer.
Get Features
You can get it from the Features project page. It is currently available for both Drupal 6 and Drupal 7.
Diff
If you are using Features, you need to use the Diff module as well. Your features might become overridden, which means that what is in the database does not match what is in code. When this happens, you can use the Diff module to see the difference. You can also view changes between two revisions of nodes, modules etc. The diff module will save you a tonne of time.
Get Diff
You can get it from the Diff project page. It is currently available for both Drupal 6 and Drupal 7.
Hacked
See if any contrib modules have been overridden since being downloaded. You can use it with Diff to see the differences, line by line. This is particularly useful if you are taking over a Drupal site from another developer, or working with a team where you don’t know what everyone is doing. It is bad practice to hack core or contrib modules but you don’t always know if something has changed and there isn’t always a patch file to help you. (Note: if you must change a contrib or core module, always create a patch file so you can reply it after applying updates).
Get Hacked
You can get it from the Hacked project page. It is currently available for both Drupal 6 and Drupal 7.
Backup and Migrate
Backup and Migrate makes it very easy to backup your database. You can back up with one click in the admin interface, or my running one Drush command (drush bam-backup). You can also configure it to send your backups to services such as Dropbox or Amazon S3.
Get Backup and Migrate
You can get it from the Backup and Migrate project page. It is currently available for Drupal 5, Drupal 6 and Drupal 7.
API Reference site and Drupal Contrib API site
The default Drupal API documentation can be found here - api.drupal.org. This is a brilliant resource for core functions and hooks.
Documentation for popular Drupal contributed moulded can be found on DrupalContrib. It is to contrib modules what api.drupal.org is to core.
Repository Viewer
Sometimes the easiest way to understand how a module works is to read the code. But it is a pain to have to download it first. You don’t have to. On the modules’ project page, there is the Repository Viewer link, which allows you to view the code in full, right in the browser.
Masquerade
Often when developing Drupal, you need to test something as a different user. In fact, you should get used to not testing as the admin user! You need to ensure the permissions for various users and roles work. The Masquerade module allows you to easily switch to a different user. It is also very useful when a particular user reports a bug and you need to replicate exactly what they are doing.
Get Masquerade
You can get it from the Masquerade project page. It is currently available for Drupal 6 and Drupal 7.
Drupal for Firebug
This allows you to see useful information about nodes, users, SQL queries and execute PHP right from Firebug. If you don’t want to use Firefox, there is also Drupal for Chrome.
Get Drupal for Firebug or Drupal for Chrome
You can get the Drupal code from the Drupal for Firebug project page.
If you are using Firefox, you can get the official plugin from the Mozilla, or the latest version from the DrupalForFirebug repository.
If you are using Chrome, you can get the plugin for Drupal for Chrome.
Administration menu
This is not really a development tool as such, but the admin menu makes navigating around the admin interface a LOT faster. How? Less clicks. It provides a bar across the top of the screen and a hierarchical drop down for each admin link, so you only have to click once to go to a specific admin page. Most of the other Drupal menus force you to click multiple times for deep links.
Get Administration Menu
You can get it from the Administration menu project page. It is currently available for Drupal 6 and Drupal 7.
Production Check, Production Monitor and Performance
The Production Check module gives you the status of essential modules for production sites. It tells you whether or not they are disabled and information about critical errors. It covers caching, aggregation, compression, APC, PHP errors, SEO modules and development modules such as Devel (which should be disabled on a production site).
You can use the Production Monitor module to add any number of sites to your local site and get Product Check on them. This makes it very easy to check all of your production sites from one single place.
It even has integration with the Performance module, so you can monitor page generation times, memory usage etc for your production websites.
Get Production Check, Production Monitor
You can get it from the Production check & Production monitor project page. It is currently available for Drupal 6 and Drupal 7.
Get Performance
You can get it from the Performance project page. It is currently available for Drupal 6 and Drupal 7.
Drupal Project Lookup
Drupal Project Lookup is a Chrome extension which saves time when searching for a project page on drupal.org. To use it, you type pml followed by the project you are looking for. For example, to go to the Views project page, type “pml views”. This will take you to https://drupal.org/project/views
Get Drupal Project Lookup
You can Drupal Project Lookup from the Chrome web store.
Drupal API Search
Drupal API Search is a Chrome extension that saves time when searching for API documentation on api.drupal.org. To use it, type dr followed by function name you are looking for. It will autocomplete as you type. For example, to go to the API documentation for hook_form_alter, type “dr hook_form_alter”. This will take you to https://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_form_alter/6.
It defaults to Drupal 6 pages on api.drupal.org. You can change this by going to your chrome extensions page (chrome://extensions/), and clicking options for Drupal API Search. There you can change the Drupal version to 7 or 8.
Get Drupal API Search
You can get Drupal API Search from the Chrome web store.
Dreditor
Dreditor improves the experience of reviewing patches and commenting on issues on drupal.org. Its features include:
- Adds a patch reviewer button to patches in issues on drupal.org. After you click on the review button, you will get a nice patch file with syntax highlighting.
- Provides Auto-completion when adding comments on Drupal.org.
- Makes it easier to attach screenshots to issues
- Provides a template for commit messages
Get Dreditor
You can get Dreditor from its website.
Non-Drupal specific tools
There is a bunch of other tools that you may need to make your life easier developing Drupal modules and themes.
- Code editor or IDE.
I use PhpStorm for a kick ass IDE or Sublime Text for a great code editor. - MySQL GUI
You can use the command line to interact with MySQL, but you might find it easier to use a GUI.
PhpMyAdmin is the standard that you will find in a lot of places, including most hosting providers. For Mac, Sequel Pro is fast, slick and easy to use. - Snippet manager
There is lots of little (and big) bits of code that will be reused and it makes sense to store these in a snippet manager so you can easily reuse them. A lot of IDEs and code editors provide this functionality. I use a 3rd part tool because I often change IDEs, but want to retain the same snippet repo. I use Snippets (Mac only). - Xdebug
Xdebug is a debugging and profiling tool for Drupal. It allows you to step through your code, line by line, as a request is being returned. If you have a bug and you don’t know which bit of code is causing it, Xdebug can be a real timesaver. Even if you are not trying to identify a bug, this is a very useful exercise just to see all of the code that is run when Drupal is dealing with a request for a particular URL. - CSS preprocesser
Organise your CSS code and make it much easier to developer and maintaining with a CSS preprocesser The two most popular are Sass and Less. If you use Sass, then I recommend you use Compass as well.
Other tools worth mentioning
The following tools are not essential, especially if you are just starting with Drupal development. I have listed them here for completeness and you may find yourself needing to use them at some stage.
- Vagrant for creating a virtual development environment and Puppet or Chef for configuration management.
- VMWare - run a LAMP stack on Mac or Windows, as an alternative to Vagrant.
- XAMPP (cross platform), WampServer(Windows) or MAMP(Mac) for a development environment if you don’t want the hassle of setting one up with Vagrant or VMWare.
- Aegir is a system that makes it easier to deploy and manage multiple Drupal sites and servers. Aegir automates the process of creating server configuration files, databases and Drupal installation. There are additional AEgir based systems such as Barracuda, Octopusand DevShop.
- Behat / PHP Unit / Simple Test / Selenium for automated testing
- Kcachegrind / jMeter / Apache Bench for Performance testing.
- XHProf Code Profiler for profiling. Profiling is to measure the execution time for function or method calls when an application is dealing with a page request.
- New Relic to help you identify performance issues so you can create a faster application
- Deadwood to makes it easier to upgrade a module for a new major version of Drupal. It is now merged into Coder and is called Coder Upgrade, but you still need Deadwood if upgrading from Drupal 5 to 6.
- Schema for additional functionality not provided by the Schema API
Sunday, December 4, 2011
Setup for Linux Memcached (daemon) with PHP PECL Memcache and Drupal Memcache Module - with localized UNIX sockets
This information enhances some documentation for the Drupal Project Memcache -> http://drupal.org/project/memcache
Revision Notes PHP: I have tested both PECL Memcache and PECL Memcached versions, and for the moment see less 'bugs' with the use of PECL memcache.
Suggested 'priority' - is to get the latest [memcache] release at http://svn.php.net/viewvc/pecl/memcache/
It has several improved 'features' - including the option to use faster 'localized' Unix 'sockets'
2) Sample 'memcache php.ini' settings:
3) Sample Linux memcached daemon /etc/init.d/memcached script:
Notes: Above examples taken from my own working Linux server (multi-hosts).
For the last option (Linux), I used
eg:
Additional Notes: The PHP Memcache PECL can also be compiled fully 'static' into the php-5.3.x binary-by moving the [memcache - PECL] source into the php /ext folder and rebuilding the PHP 'buildconf' - then compile PHP 5.3.x with --enable-memcache (it is *not* essential to use PECL if you are after the best speed - and understand *static* PHP compile builds).
PHP 5.3.x Static Compile guidelines:
In the PHP source root folder, issue the following (Linux);
Then compile PHP manually (or use rpmbuild or similar). I usually work direct with Fedora RPM sources, hence I used;
This method works well for me on my multi-hosted Linux dedicated server.
Revison #1 Doc's by peter bowey http://drupal.org/user/564804
Peter Bowey Computer Solutions
http://www.pbcomp.com.au/
Revision Notes PHP: I have tested both PECL Memcache and PECL Memcached versions, and for the moment see less 'bugs' with the use of PECL memcache.
Suggested 'priority' - is to get the latest [memcache] release at http://svn.php.net/viewvc/pecl/memcache/
It has several improved 'features' - including the option to use faster 'localized' Unix 'sockets'
Memcache - Guidelines: see items 1) to 3)
1) A typical Drupal / Pressflow 6.2x use of memcache - via settings.php is: (copied form my own Linux server + based on fast [local] sockets for memcache)<?php/**
* Memcache:
*/$conf += array(
'memcache_extension' => 'memcache',
'show_memcache_statistics' => 0,
'memcache_persistent' => TRUE,
'memcache_stampede_protection' => TRUE,
'memcache_stampede_semaphore' => 15,
'memcache_stampede_wait_time' => 5,
'memcache_stampede_wait_limit' => 3,
'memcache_key_prefix' => basename(realpath(conf_path())),
);
// We don't use chained memcached caching for sites cron, php-cli and install!if (isset($_SERVER['HTTP_USER_AGENT']) && !preg_match("/(?:cron\.php|install\.php)/", $_SERVER['REQUEST_URI'])) {
if (isset($_SERVER['HTTP_HOST'])) {
$conf += array(
'cache_inc' => './sites/all/modules/memcache/memcache.inc',
'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
'lock_inc' => './sites/all/modules/memcache/memcache-lock.inc',
'memcache_servers' => array(
'unix:///tmp/memcached.socket0:0' => 'default',
'unix:///tmp/memcached.socket1:0' => 'block',
'unix:///tmp/memcached.socket2:0' => 'content',
'unix:///tmp/memcached.socket3:0' => 'filter',
'unix:///tmp/memcached.socket4:0' => 'form',
'unix:///tmp/memcached.socket5:0' => 'menu',
'unix:///tmp/memcached.socket6:0' => 'page',
'unix:///tmp/memcached.socket7:0' => 'update',
'unix:///tmp/memcached.socket8:0' => 'views',
'unix:///tmp/memcached.socket9:0' => 'session',
'unix:///tmp/memcached.socket10:0' => 'users'
),
'memcache_bins' => array(
'cache' => 'default',
'cache_block' => 'block',
'cache_content' => 'content',
'cache_filter' => 'filter',
'cache_form' => 'form',
'cache_menu' => 'menu',
'cache_page' => 'page',
'cache_update' => 'update',
'cache_views' => 'views',
'session' => 'session',
'users' => 'users'
),
);
}
}?>
[memcache]
; Data will be transferred in chunks of this size
memcache.chunk_size = 32768
memcache.hash_strategy = consistent
memcache.default_port = 0
session.save_handler = memcache
session.save_path = "unix:///tmp/memcached.socket11:0?persistent=1&weight=1&timeout=1&retry_interval=15"
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached-multi daemon is a network memory cache service.
# processname: memcached-multi
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached/memcached.*.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT=11211
UDP=0
SOCKET=/tmp/memcached.socket
VAR=0
USER=memcached
MAXCONN=300
CACHESIZE=64
OPTIONS=""
if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
start_instance() {
echo -n $"Starting $prog ($1): "
# daemon --pidfile /var/run/memcached/memcached.$1.pid memcached -d -p $PORT -u $USER -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS
daemon --pidfile /var/run/memcached/memcached.$1.pid memcached -d -s $3 -a 766 -L -t 8 -u $USER -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached.$1
}
stop_instance() {
echo -n $"Stopping $prog ($1): "
killproc -p /var/run/memcached/memcached.$1.pid /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached.$1
rm -f /var/run/memcached.$1.pid
fi
}
start() {
# insure that /var/run/memcached has proper permissions
if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
chown $USER /var/run/memcached
fi
# we start 12 socket streams for memcached
start_instance default 64 /tmp/memcached.socket0;
start_instance block 64 /tmp/memcached.socket1;
start_instance content 64 /tmp/memcached.socket2;
start_instance filter 64 /tmp/memcached.socket3;
start_instance form 64 /tmp/memcached.socket4;
start_instance menu 64 /tmp/memcached.socket5;
start_instance page 64 /tmp/memcached.socket6;
start_instance update 64 /tmp/memcached.socket7;
start_instance views 64 /tmp/memcached.socket8;
start_instance session 64 /tmp/memcached.socket9;
start_instance users 64 /tmp/memcached.socket10;
start_instance pbold 64 /tmp/memcached.socket11;
}
stop () {
stop_instance default;
stop_instance block;
stop_instance content;
stop_instance filter;
stop_instance form;
stop_instance menu;
stop_instance page;
stop_instance update;
stop_instance views;
stop_instance session;
stop_instance users;
stop_instance pbold;
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload|force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
exit 1
esac
exit $?
For the last option (Linux), I used
"yum install memcached"
eg:
yum search memcached
>
memcached.x86_64 : High Performance, Distributed Memory Object Cache
Additional Notes: The PHP Memcache PECL can also be compiled fully 'static' into the php-5.3.x binary-by moving the [memcache - PECL] source into the php /ext folder and rebuilding the PHP 'buildconf' - then compile PHP 5.3.x with --enable-memcache (it is *not* essential to use PECL if you are after the best speed - and understand *static* PHP compile builds).
PHP 5.3.x Static Compile guidelines:
In the PHP source root folder, issue the following (Linux);
rm configure
PHP_AUTOCONF=autoconf-2.13 PHP_AUTOHEADER=autoheader-2.13 ./buildconf --force
Then compile PHP manually (or use rpmbuild or similar). I usually work direct with Fedora RPM sources, hence I used;
rpmbuild -bb php.spec >> php.checklist 2>&1
Using Unix Sockets with the Drupal Memcache Project:
To use Linux sockets with the Drupal memcache module - please refer to: http://drupal.org/node/538426This method works well for me on my multi-hosted Linux dedicated server.
Current Changelog for PHP PECL memcache
: from http://pecl.php.net/package-changelog.php?package=memcache&release=3.0.63.0.6 - Fixed PECL Bug #16672 (memcache.php doesn't support unix socket)
- Fixed PECL Bug #19374 (memcache.php throws Notice: Undefined index: VALUE when viewing expired items)
- Fixed PECL Bug #17518 (Strange behavior in increment on non integer and after)
- Fixed potential segfault in memcache queue.
- Fixed various tests
Revison #1 Doc's by peter bowey http://drupal.org/user/564804
Peter Bowey Computer Solutions
http://www.pbcomp.com.au/
Memcache in Drupal
The Memcache contributed project provides memcache integration, and support for Drupal's caching, session, and lock backends.
These are the broad steps you need to take in order to use this software on Drupal 6.x.Information pertaining to the Drupal 7.x version is also found in the README.txt file from the module distribution.
For 6.x (order is important):
If you want the simple version, you can start one default memcache instance on your web server like this: memcached -m 24 -p 11211 -d If that is enough to meet your needs, there is no more configuration needed. If you want to utilize this module's sophisticated clustering feature and spread your cache over several machines, or if your cache is found on a machine other than your web server, read on.
You should probably lock down the memcache server so that it only listens for connections from the hosts that need to be served, as the default is that memcache listens to connections from all addresses. So, to close that hole, edit /etc/sysconfig/memcached with:
For example:
The available memcached servers are specified in $conf in settings.php. If you do not specify any servers, memcache.inc assumes that you have a memcached instance running on 127.0.0.1:11211. If this is true, and it is the only memcached instance you wish to use, no further configuration is required.
If you have more than one memcached instance running, you need to add two arrays to
WARNING: Avoid the use of "localhost" and instead use real IP addresses or hostnames that will remain consistent across the network.
The bin/cluster/server model can be described as follows:
?>
Here is an example configuration that has two clusters, 'default' and 'cluster2'. Five memcached instances are divided up between the two clusters. 'cache_filter' and 'cache_menu' bins go to 'cluster2'. All other bins go to 'default'.
D6:
?>
D7:
Here is a sample config that uses memcache for sessions. Note you MUST have
a session and a users server set up for memcached sessions to work.
SOLUTION: Upgrade your PECL library to PECL package (2.2.1) (or higher).
PROBLEM: WARNING: Zlib compression at the php.ini level and Memcache conflict.
SOLUTION: See http://drupal.org/node/273824
way to clear the cache, and an interface to organize servers, bins, and clusters.
it will be used by default. This new extension backends to libmemcached and
allows you to use some of the newer advanced features in memcached 1.4.
NOTE: It is important to realize that the memcache php.ini options do not impact
the memcached extension, this new extension doesn't read in options that way.
Instead, it takes options directly from Drupal. Because of this, you must
configure memcached in settings.php. Please look here for possible options:
http://us2.php.net/manual/en/memcached.constants.php
An example configuration block is below, this block also illustrates our
default options. These will be set unless overridden in settings.php.
These are as follows:
which is more advanced and faster, by adding the following to settings.php:
Requirements
- PHP 5.1 or greater
- Availability of a memcached daemon
- One of the two PECL memcache packages: memcache PECL package or memcached PECL package
Installation
These are the broad steps you need to take in order to use this software on Drupal 6.x.Information pertaining to the Drupal 7.x version is also found in the README.txt file from the module distribution.
For 6.x (order is important):
- Install the memcached binaries on your server. See How to install Memcache on Debian Etch or How to install Memcache on OSX
- Install the PECL memcache extension for PHP.
- In php.ini set memcache.hash_strategy="consistent".
- Put your site into offline mode.
- Download and install the memcache module.
- If you have previously been running the memcache module, run update.php.
- Start at least one instance of memcached on your server.
- Edit settings.php to configure the servers, clusters and bins that memcache is supposed to use. (see code snippet below)
- Edit settings.php to include memcache.inc. For example, $conf['cache_inc'] ='sites/all/modules/memcache/memcache.inc';
- Bring your site back online.
- Install the memcached binaries on your server. See How to install Memcache on Debian Etch or How to install Memcache on OSX
- Install the PECL memcache extension for PHP. This must be version 2.2.1 or
higher or you will experience errors. - Put your site into offline mode.
- Download and install the memcache module.
- If you have previously been running the memcache module, run update.php.
- Start at least one instance of memcached on your server.
- Edit settings.php to mke memcache the default cache class, for example:
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal'; - Bring your site back online.
Servers
NOTE: As of 6.15, it is possible to efficiently run memcache in one daemon, shared by all bins. You can safely ignore advice found elsewhere on the internet that advises one memcached daemon per bin. In terms of reporting, there are still some advantages to having more daemons.If you want the simple version, you can start one default memcache instance on your web server like this: memcached -m 24 -p 11211 -d If that is enough to meet your needs, there is no more configuration needed. If you want to utilize this module's sophisticated clustering feature and spread your cache over several machines, or if your cache is found on a machine other than your web server, read on.
You should probably lock down the memcache server so that it only listens for connections from the hosts that need to be served, as the default is that memcache listens to connections from all addresses. So, to close that hole, edit /etc/sysconfig/memcached with:
OPTIONS="-l ${HOSTIP}"
For example:
OPTIONS="-l 127.0.0.1"
The available memcached servers are specified in $conf in settings.php. If you do not specify any servers, memcache.inc assumes that you have a memcached instance running on 127.0.0.1:11211. If this is true, and it is the only memcached instance you wish to use, no further configuration is required.
If you have more than one memcached instance running, you need to add two arrays to
$conf;
memcache_servers and memcache_bins. The arrays follow this pattern:<?php'memcache_servers' => array(host1:port => cluster, host2:port => cluster, hostN:port => cluster)'memcache_bins' => array(bin1 => cluster, bin2 => cluster, binN => cluster)?>
The bin/cluster/server model can be described as follows:
- Servers are memcached instances identified by host:port.
- Bins are groups of data that get cached together and map 1:1 to the $table param in cache_set(). Examples from Drupal core are cache_filter, cache_menu. The default is 'cache'.
- Clusters are groups of servers that act as a memory pool.
- Many bins can be assigned to a cluster.
- The default cluster is 'default'.
<?php
$conf = array(
'memcache_servers' => array('10.1.1.1:11211' => 'default',
'10.1.1.1:11212' => 'pages'),
'memcache_bins' => array('cache_page' => 'pages'),
);?>
Here is an example configuration that has two clusters, 'default' and 'cluster2'. Five memcached instances are divided up between the two clusters. 'cache_filter' and 'cache_menu' bins go to 'cluster2'. All other bins go to 'default'.
D6:
<?php
$conf = array(
'cache_inc' => './sites/all/modules/memcache/memcache.inc',
'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'),
'memcache_bins' => array('cache' => 'default',
'cache_filter' => 'cluster2',
'cache_menu' => 'cluster2'),
);?>
?>
D7:
<?php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';$conf['cache_default_class'] = 'MemCacheDrupal';$conf = array(
'cache_default_class' = 'MemCacheDrupal',
'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'),
'memcache_bins' => array('cache' => 'default',
'cache_filter' => 'cluster2',
'cache_menu' => 'cluster2'),
);?>
Prefixing
If you want to have multiple Drupal installations share memcached instances, you need to include a unique prefix for each Drupal installation in the$conf
array of settings.php:<?php
$conf = array(
'memcache_key_prefix' => 'something_unique',
);?>
Sessions
NOTE: Session.inc is not yet ported to Drupal 7.Here is a sample config that uses memcache for sessions. Note you MUST have
a session and a users server set up for memcached sessions to work.
<?phpinclude_once('./includes/cache.inc');
include_once('./sites/all/modules/memcache/memcache.inc');$conf = array(
'cache_default_class' = 'MemCacheDrupal',
'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
'memcache_servers' => array(
'localhost:11211' => 'default',
'localhost:11212' => 'filter',
'localhost:11213' => 'menu',
'localhost:11214' => 'page',
'localhost:11215' => 'session',
'localhost:11216' => 'users',
),
'memcache_bins' => array(
'cache' => 'default',
'cache_filter' => 'filter',
'cache_menu' => 'menu',
'cache_page' => 'page',
'session' => 'session',
'users' => 'users',
),
);?>
Troubleshooting
PROBLEM: Error: Failed to set key: Failed to set key: cache_page-......SOLUTION: Upgrade your PECL library to PECL package (2.2.1) (or higher).
PROBLEM: WARNING: Zlib compression at the php.ini level and Memcache conflict.
SOLUTION: See http://drupal.org/node/273824
Memcache Admin
A module offering a UI for memcache is included. It provides stats, away to clear the cache, and an interface to organize servers, bins, and clusters.
Memcached PECL Extension Support
We also now support the Memcached PECL extension. If you install this extension,it will be used by default. This new extension backends to libmemcached and
allows you to use some of the newer advanced features in memcached 1.4.
NOTE: It is important to realize that the memcache php.ini options do not impact
the memcached extension, this new extension doesn't read in options that way.
Instead, it takes options directly from Drupal. Because of this, you must
configure memcached in settings.php. Please look here for possible options:
http://us2.php.net/manual/en/memcached.constants.php
An example configuration block is below, this block also illustrates our
default options. These will be set unless overridden in settings.php.
<?php
$conf['memcache_options'] = array(
Memcached::OPT_COMPRESSION => FALSE,
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
);?>
- Turn off compression, as this takes more CPU cycles than its worth for most
users
- Turn on consistent distribution, which allows you to add/remove servers
easily
which is more advanced and faster, by adding the following to settings.php:
<?php
$conf['memcache_options'] = array(
Memcached::OPT_BINARY_PROTOCOL => TRUE,
);?>
Setup for Linux Memcached (daemon) with PHP PECL Memcache and Drupal Memcache Module - with localized UNIX sockets
Subscribe to:
Posts (Atom)