Drupal

Drupal6 - Programatically create new date type and date format

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;
  date_format_save($format);  
 
  $format_type = array();
  $format_type['title'] = 'month_day';

CodeLobster PHP IDE for Drupal development

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

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.

Drush 4 : Automated Drupal Site Database Backups made easy

Following the release of Drush 4 and picking up on a couple of suggestions made by Moshe Weitzman and Nick Thompson on my previous Drush 3 Automated backup post, it was time for a revised post.

Drush 4 makes it really REALLY easy to backup all your sites, no more bash scripting etc.

Install / Update to Drush 4

Varnish Cookie Tweak to allow Anonymous Comments with Pressflow

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

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

Drupal 6 - Disable CK Editor wysiwyg programmatically

Need to disable the CK Editor programmatically for specific form fields?

New form method

function mymodule_settings_form() {
  $form['foobar'] = array(
    '#type' => 'textarea', 
    '#title' => t('foobar'), 
    '#default_value' => "foobar", 
    '#required' => FALSE,
    '#wysiwyg' => FALSE,
  );
 
  return system_settings_form($form);
}

form alter method

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'mymodule_settings_form') {
    $form['foobar']['#wysiwyg'] = FALSE;
  } 
}

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

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

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

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

extension=memcache.so
memcache.hash_strategy="consistent"

Syndicate content