Drupal6 - Programatically create new date type and date format

Submitted by Janak on Tue, 11/22/2011 - 11:46

If you are working with code based deployments instead of using CMS to push out changes, you might have already implemented something similar.

There are 2 approches to implementing this:

1) Define and save date formats

function mymodule_custom_date() {
  $date_format_monthday = 'm-d';
  $format = array();
  $format['format'] = $date_format_monthday;
  $format['type'] = 'custom';
  $format['locked'] = 0;
  $format['is_new'] = 1;
  $format_type = array();
  $format_type['title'] = 'month_day';

CodeLobster PHP IDE for Drupal development

Submitted by Janak on Tue, 09/13/2011 - 16:04

I received an invite to review CodeLobster - A new, feature rich, PHP IDE on the scene with very good support for Drupal and Wordpress among other CMS and Frameworks.

As a Drupal developer, the focus of this short introduction will be Drupal integration (obviously).

Among standard CodeLobster IDE features (free version), it has some very interesting support for Drupal development (pro version), one of the things many find lacking in many IDEs is out of the box Drupal support for Auto complete, API integration etc.

Varnish Cache - Memory, Hitrate & Bandwidth Optimisation for Drupal Pressflow

Submitted by Janak on Tue, 01/11/2011 - 16:39

Recently I started to notice I very high number of LRU Nuked Objects on my websites, which was essentially wipping the entire Varnish Cache. I run Varnish with 4GB File cache and site ocntent is mostly served by external "Poor Man CDN". So, in theory my site content should not be anything near 4GB, however, Varnish Cache was running out of memory and "Nuking" cached objects.

Sizing your cache

Here is what Varnish Cache man pages have to say:

Watch the n_lru_nuked counter with varnishstat or some other tool. If you have a lot of LRU activity then your cache is evicting objects due to space constraints and you should consider increasing the size of the cache.

Varnish Cookie Tweak to allow Anonymous Comments with Pressflow

Submitted by Janak on Wed, 12/29/2010 - 13:28

If you are using Drupal and have allowed anonymous user to leave comments on the site, you will notice that the core comments module adds two cookies named comment_info_name and comment_info_mail. These cookies allow the comments form to be auto populated with name and email on any subsequent comments from the same user.

For majority of users this is not something of a concern. Whist this is useful, if any cookies are passed back from client side in the request, Varnish will simply request the page from the back end instead of requesting the page from the cache. This will result in many cache MISSes as the cookie is set for 365 days (!!!!)

Automated Drupal database backups using Drush, Bash and Cron

Submitted by Janak on Thu, 12/23/2010 - 10:19

Drush + Bash + Cron: Datbase Backup Goals

  • Scan sites directory for a given drupal install
  • Find all multisite folders/symlinks
  • For each multisite:
  • Use Drush to clear cache - we dont want cache table bloating up the MySQL dump file
  • Use Drush to delete watchdog logs - we dont want watchdog table bloating up the MySQL dump file
  • Use Drush to backup the database to pre-assigned folder
  • Use tar to compress and timestamp the Drush generated sql file

Varnish and Pressflow (Drupal) - Improve HIT rate and SEO - 301 redirects using Varnish

Submitted by Janak on Mon, 10/04/2010 - 18:52

Following on from previous post about VCL tweaks to improve hitrate; there are occasions when a website should not be served from both www.foobar.com and http://foobar.com. In some instances Google will deem the content to be duplicate copy of each other and a website can suffer from dupe content penalty.

Varnish and Pressflow (Drupal) - VCL tweaks for achieving a high hitrate

Submitted by Janak on Thu, 09/30/2010 - 11:58

The default Varnish config for Pressflow by Four Kitchens is an excellent starting point and gets you up and running with relatively little pain and effort. Having done a fair amount of Varnish tweaking for my personal and work websites, I came across a couple of varnish tweaks that resulted in a phenominal improvement in Varnish Hit rate.

Vary User Agent

Install Memcache for Drupal on CentOS 5.5

Submitted by Janak on Mon, 09/27/2010 - 17:21

Install EPEL Repo

Memcache can be found in the EPEL repo. Install EPEL repo:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Install Memcache

yum install memcached
pecl install memcache
yum install zlib-devel

Auto start memcache on reboot

chkconfig --level 2345 memcached on

Add PHP settings for Memcache

nano /etc/php.d/memcache.ini