The init hook enigma

I wasted a few hours on figuring out why an init hook in one of my modules wasn't invoked when normal page caching was on. Turns out the boostrap field in the system table for my module was still 0, instead of 1. So remember boys and girls, when you allready enabled your own custom module and you add an hook_init, remember to disable and enable your module again so Drupal knows it exists. Or manually alter the record in the system table in your database if disabling the module breaks your site.

On the bright side, I think I know every line of bootstrap.inc and cache.inc file now by heart.

Topics 

drupal, hooks

Drupal on lighttpd with clean urls made easy

Apache is and will be one of the best/popular webservers out there for years for most websites, but nowadays, when it comes to scalability, load, performance and speed, my first choice of webserver is lighttpd, also called lighty. It took me some months to create the perfect configuration for a Drupal site with a lot modules but I think I finally found it. My setup is used for Drupal 5.3 (and for the first time on a new site called CarChannel, cf http://realize.be/carchannel), but will be more or less the same for the upcoming 6.x release in a few months. And even if you keep using apache, the rest of this article still is interesting to gain more speed for your Drupal setup with more caching tips!

Lighttpd and clean URL's - http://www.lighttpd.net/
I was very impressed with a previous project we launched at work using lighttpd instead of apache. The load on the machine constantly kept under 0.40 having more then 1 million hits per day. Time to check if Drupal would run also as smooth on this server. Lighttpd doesn't support mod_rewrite like Apache does, but after lots of googling, I finally found the solution which also enables clean urls and keeps everything running as it should. The answer is LUA and mod_magnet. No more exotic rewrite rules in your lighttpd.conf which always caused problems at some point. I'm not going to explain it here again for you, all credits go to other authors for creating this configuration. Read following pages to make your sites fly

When all is done, your Drupal setup works with clean urls and yes imagecache works fine! An excerpt of my local lighttpd.conf configuration is underneath:

server.modules = (
   "mod_access",
   "mod_fastcgi",
   "mod_magnet",
   "mod_simple_vhost",
)

fastcgi.server =
   ( ".php" =>
     ( "localhost" =>
       (
         "socket" => "/var/run/lighttpd/php-fastcgi.socket",
         "bin-path" => "/usr/bin/php-cgi"
       )
     )
   )

url.access-deny = ( "~", ".inc", ".engine", ".install", ".module", ".sh", "sql", ".theme", ".tpl.php", ".xtmpl", "Entries", "Repository", "Root" )

$HTTP["host"] =~ "(^|\.)connector$" {
  index-file.names = ( "index.php" )
  simple-vhost.server-root   = "/home/"
  simple-vhost.default-host  = "projects"
  simple-vhost.document-root = "connector"
  magnet.attract-physical-path-to = ( "/etc/lighttpd/drupal.lua" )
  server.errorlog             = "/var/log/lighttpd/connector-error.log"
  accesslog.filename             = "/var/log/lighttpd/connector-access.log"
}

XCache - http://xcache.lighttpd.net
XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load. It is tested (on linux) and supported on all of the latest PHP cvs branches such as PHP_4_3 PHP_4_4 PHP_5_0 PHP_5_1 PHP_5_2 HEAD(6.x). ThreadSafe/Windows is also supported. It overcomes a lot of problems that has been with other competing opcachers such as being able to be used with new PHP versions. Does the same thing like APC and I really prefer this one, because running APC with PHP5 on lighty was a nightmare. XCache seems to do the job well without segfaulting every hour.

APC - http://be.php.net/apc
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. This framework will keep your scripts in a compiled form in memory, so every script doesn't have to be interpreted with every call you make to your website. The PECL package is not bundled in the PHP package itself, but is easy installable by just typing 'pecl install apc'. After that just add 'extension=apc.so' to your php.ini and restart your webserver. Warning: running with PHP5 is unstable, PHP4 runs perfect.

Both opcache codes optimize the speed results sometimes by 5!

MySQL Query Cache - http://dev.mysql.com/doc/refman/5.0/en/query-cache.html
The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. No further explanation is needed I guess.

Drupal settings
Drupal comes with it's own caching and speed tricks. Enable normal page caching for anonymous users which results in less database queries and faster page loads. Logged-in visitors don't benefit from the caching, but read on if you also want to have a decent caching for those users! You can also aggregate css files when your site is production. Drupal 6 also supports this feature for all javascript files, great! Drupal core also ships the throttle module which handles site congestion. I've personally never used it, but it's worth mentioning it.

Module: Block Cache - http://drupal.org/project/blockcache
"This module creates a cached version of each block. Block caching happens separately from page caching and so it will work for logged-in users whether or not page caching is enabled for the site." This is a huge advantage because it can reduce complex queries or calculations needed for some blocks. The interface also permits you to set a cache expiry time and whether it's a page and/or user specific content block. Highly recommended! Note: block cache is in core starting from Drupal 6.x!

Module: Advanced Cache - http://drupal.org/project/advcache
"The advanced caching module is mostly a set of patches and a supporting module to bring caching to Drupal core in places where it is needed yet currently unavailable. These include caching nodes, comments, taxonomy (terms, trees, vocabularies and terms-per-node), path aliases, and search results." The only small downside in my opinion is that when a new release of Drupal core is out, you really need to re-apply these patches and sometimes need to patch files manually. At the time of this writing, an official Drupal 5.3 release isn't out there, but the patches are allready available on http://drupal.org/node/184522. Only use if if you think it's really worth it.

Module: Memcache - http://drupal.org/project/memcache
An API for using Memcached and the PECL Memcache library with Drupal. Instead of storing the data into the database, cached data is available in memory. At this time, it seems to be broken with the 5.3 release. Tests with 5.2 work fine, so let's hope a new release is out soon, because together with all previous settings, the boost performance is enormous!

That's it. After reading this, you should be able to make your new site fly, happy tuning! When I find some time, I'll try and generate some benchmark reports, but I'm pretty sure you will feel the difference yourself. You can also read http://drupal.org/node/2601 on drupal.org which handles the same topic, interesting for all you sysadmins out there.

CarChannel

From a far away place I can announce my colleagues at One Agency succesfully launched a new Drupal-powered site, called CarChannel. Although my father is an auto mechanician, I've never been very interested in what's really going on inside a car and I don't really prefer one model. The fact that the CarChannel site has everything to do with cars didn't change that fact, I was mostly interested making sure I got a topspeed site with Drupal with cool features which also looked nice. It's built on 5.3 and for the first time I'm running it on a lighttpd server *with* clean URLS enabled without any problems, even the imagecache module behaves like it should! But anyways, all you people interested in the latest news on cars with lot's of pictures and cool video's, do check out the site. You can even create your own video channel but only with external video content in fase 1. In fase 2 (I guess somewhere in december) you'll be able to add your home made video's of your tuned car!

Topics 

drupal, work, cars

tagcloud

Nowadays, I think everybody knows what a Tag Cloud is. It's typically associated with 'web 2.0' - you're free to fill in your own definition of that word. At work today, we received a mail from someone who seems to be higly educated, at least, that's what we think especially since he's a professor on some university. In his mail he talked about 'evocations of thematics' (for the Dutch people: evocaties der thematieken) which he would gladly see on his new website. Although there are almost 30 people at our office, no one really knew what he was talking about, so for this small matter we contacted him and after some explanation we finally realised he was talking about a Tag Cloud. Anybody who has more cool descriptions of common known web terms, feel free to comment!

In the meantime, we did a softlaunch - or a beta-launch as I googlely call it - of the Connectr site. I still have to squash some small bugs, add a few extra features to it and reconfigure the server setup (lighttpd with fastcgi all the way, f*ck apache) before I leave on holiday in november, but I'm quite glad allready with the result. It's built on the Drupal platform and uses external sites like Garagetv and Google for video & maps. Fun to work on, so let's hope this gets some good traffic when the big promotion campaign begins. For those interested in cars, mark the 8th of november, yours truly really built something cool for you!

Topics 

drupal, work

Eurodisney

Thanks to Nadia, who works at Disney, we got 6 free tickets to spent the whole weekend at Eurodisney in Paris! If you're able to block out the constant musac, it's actually a great place to walk around and revive your childhood memories. Of course, there's quite good action too, especially with the Space Mountain, Star (Wars!) Tours, Aerosmith rollercoaster and so on. There's even a cool show with a crew of stuntman performing a carchase on a huge filmset with explosions, gunfire .. even Herbie shows up at a certain point. One thing's for sure: exciting carchases in movies will never be the same anymore after I've seen the clever tricks the film industry is using. Big thanks to Nadi again!

Topics 

holiday

Pages

Subscribe to realize.be RSS