Drupal tips and tricks

The small things that make life easier with Drupal

Speeding up Drupal on Vista with Wampserver

Submitted by Frederic Marand on

The problem : Drupal awfully slow on Vista (and Seven) with Wampserver

For some time now, I'd been severiously annoyed by the (utter lack of) performance of Drupal 6 and 7 on my home PC, which happens to be running Microsoft Vista: considering I was used to getting page times around 200ms on a fractional Celeron with Apache 2.2 on a Linux server hosted comparatively far across the net from that same machine, I felt the 5 to 15 seconds response time per page on this local machine with a quad core and 3 GB RAM were really making me lose my time.

The solution

After some time spend googling around, I stumbled upon an incredibly simple tip, which made the 5 to 15 seconds per page drop down to around 1 second when logged in, and well below 500 ms when not logged in. It's incredible what ONE single character in a plain text file gets you under Vista :-)

UPDATE 2010-01-23: David Hogg tells us (see below) that this works for Windows Seven too

If the SELECT in your Drupal modules are suddenly all 4 lines high or more...

Submitted by Frederic Marand on

If all of a sudden you notice that the SELECT elements in your Drupal forms increases to 4 and any smaller size is ignored...

... maybe you've already forgotten you were using Chrome, and it is not a Drupal bug : this is a "usability" feature of WebKit. See http://trac.webkit.org/browser/trunk/WebCore/rendering/RenderListBox.cpp#L67.

Safari users are probably used to it, but for users of other browsers, this is a bit disconcerting.

Reducing system load for graphical widgets

Submitted by Frederic Marand on

Using a graphics library, be GD, ImageMagick or anything else, is convenient, but carries a price to pay: unlike most Drupal parts, which are generally database-bound, image generation is typically CPU-bound: generating many images on the fly can significantly increase the CPU load on a system, while Drupal setups are typically not optimized for this, and could result in problems if you are using Drupal on a shared hosting account. So what ?

A progress bar widget for FormsAPI

Submitted by Frederic Marand on

Forms API progress barAs a Drupal user, you certainly noticed that update.php displays a nice progress bar to make you wait during its batch operations. And maybe you also noticed theme_progress_bar in the API reference.

The question

Wouldn't it be nice to have that progress bar available as an extended version of markup that would graphically display a value in your forms without stuffing it in a markup element ?

Checkboxes in forms step by step

Submitted by Frederic Marand on

For some reason or another, I've noticed several new Drupal developers these last few days sweating on Forms API, and thought it would be nice to have a smallish example to complement the unavoidable FAPI reference and Guick start guide, for a typical non-basic form: one including set of checkboxes in a table, with a customized display, like the core user, content or modules administration forms. So follow me while we build this example.

e-Commerce sessions in Szeged

Submitted by Frederic Marand on

If you are [considering] working on an e-Commerce site, and are coming to the Szeged Drupalcon, you may be interested in several sessions around the theme. In order for your session(s) of choice to stand a chance of being actually part of the conference program, you should vote for the sessions you would like to attend.

Subjet to approval by the conference board, I will be animating/presenting a session about the internals of the e-Commerce suite: see http://szeged2008.drupalcon.org/program/sessions/developing-e-commerce for more details. If this is of interest to you, vote on the session to make sure it will indeed be included in the conference program.

When e-commerce won't create products ...

Submitted by Frederic Marand on

I was working on an existing site today, and after installing the e-commerce 3.4 suite (EC), noticed something was very weird: product type modules were enabled, all basic EC modules were there too, and yet, when I created products by hand, the "Anonymous purchase" fieldset appeared, but nothing else from EC.

Worse, when saving the new products, they were properly created in the {node} table, but never appeared in the {ec_product} table, which caused them never to appear as products in the admin products list of the product view available to users. What could be going on ?

Multisite and dynamic configuration items in Drupal : help from Apache

Submitted by Frederic Marand on

Having recently merged a number of separately configured sites into a single consolidated multisite, I found myself with URLs like:

http://www.site1.com/sites/www.site1.com/files/somefile.png

...on all except the main site of the multisite configuration.

Although img_relocator allows me to just type things like:

<img src="somefile.png" />

... and still have these URLs be automagically generated, they still appear to those users who actually look at the URLs.

Enter mod_rewrite

Abandon all hope, ye who enter here

With these sites running over Apache 2.x, mod_rewrite offers a simple way to rewrite the files URLs: in the Apache site definition file for the vhost describing the site, we can use: