Drupal 6.x

Drush PHP Memory Limit

I was banging my head against the wall this morning because Drush kept telling me that I was exhausting PHP's memory at 128MB. I finally figured out the problem and thought I'd share for others searching the internet for a solution.

The first thing I did was check my php.ini file. Sometimes PHP on the command line will use a different php.ini file than the Apache version. In my case, the php.ini file is shared for both.

Drupal Performance: Pagination and COUNT queries

Drupal's core pagination system does not scale well on large, high-traffic sites because of it's need to count the total number of items in the list. This involves wrapping the original query around a COUNT query like below.

SELECT COUNT(*) FROM (SELECT nid FROM node);

Count queries are usually very fast for tables using the MyISAM engine, but most high-traffic Drupal sites use the InnoDB engine for most of the tables.

Learn to Develop Drupal Modules with the Examples Project

If you are looking to learn the Drupal API so you can develop your own modules, check out the Examples for Developers project. It includes highly commented example code covering some of the most common features of Drupal. Versions exist for both Drupal 6 and 7.

Drupal Performance Tuning

I work on several high traffic Drupal sites that get millions of page views per month. These sites require special fine tuning to make sure they stay online under heavy load and serve pages to users quickly.

Tuning a Drupal site for performance involves looking at several layers of the web application.

  1. The Web Server
  2. The PHP code
  3. The Database and queries
  4. HTML Components
  5. Javascript

Items 1 to 3 are in the category of Back End Performance and involve delivering the main HTML document to the user's browser as quickly as possible.

Organizing your theme files in Drupal

When working on a large Drupal site, your theme can become quite complicated with dozens of templates or template overrides, images, css files, javascript files and even a massively large template.php file. Sometimes all these files will get dumped into the root of the folder making specific files difficult to find.

Here are some best practices when organizing your theme folder to make things easier to find.

CSS, Javascript and Images

Keep these files in separate folders like so:

theme-name/js/
theme-name/css/
theme-name/images/

or you may want to organize them into an assets folder like this:

theme-name/assets/js/
theme-name/assets/css/
theme-name/assets/images/

Template Files

Put all your template files into a templates directory, then further separate them by the base template type (ie. page, node, block, view).

RPX Module Features

RPX is a product from JanRain that enables websites to allow their users to registers or login using their accounts from popular 3rd party social services like Facebook, Twitter and Yahoo.

I began working on the RPX Module last summer in conjunction with some of the folks at JanRain who run the RPX service. Since that time we've made substantial progress, releasing the first full version in January.

Current Features

  • Easy RPX Registration: In order to the RPX service with your site, you need to register an account on rpxnow.com and setup an API key for your site.

Drupal Security Review

Drupal is a very secure open source project. With thousands of eyes looking at the code, security holes get patched very quickly in the core Drupal project.

However, one of the primary ways of opening up your Drupal site to security vulnerabilities is through user error. No amount of code can prevent site administrators from doing stupid things like giving anonymous users permission to edit your blog posts.

Drupal upgrade script

EDIT: The script below has been updated to work with Drush 3.x. Those using previous versions of Drush will need to edit the script appropriately. The nature of the change was to use the new Drush 3.x standard of no spaces with command names, so "drush sql dump" was changes to drush sql-dump."

Before using this script, make sure that all your contributed themes and modules are somewhere in the "sites/" directory. If they are in any other Drupal core directories, your modules and themes will be lost.

I run a handful of small Drupal sites that I can't afford to spend too much maintenance time on, but that still need to be updated with the occasional maintenance version of Drupal.

It can be quite time-consuming to manually update 4 or 5 sites each time a security release is published.

So, a couple months ago I spent an afternoon writing a shell script to automate the whole task. With a little help from Drush, it turns a 10 or 15 minute maintenance task into about 10 or 15 seconds.

Here's what it looks like.

Altering urls in Drupal

One of the great things about Drupal's taxonomy system is that category lists are generating automatically, just by tagging your content. The taxonomy module, creates a listing of the most recent nodes in each category using a path like taxonomy/term/23.

The Views module will allow you to override this default taxonomy listing and soup it up to your tastes.