Category Archives: PHP

Drupal Tip: Lightbox pop-up on page load

Just like I was, a lot people have been seeking around the web for an easy way of invoking a lightbox as a page loads.

Examples including uses javascript to trigger the lightbox. However, scripts like this one does not work with Drupal’s Lightbox 2 module.

Here is what I used to accomplish this in Drupal, by using  JQuery’s triggerHandler function to invoke the click. Hope this will help others who need an auto lightbox pop-up.

Continue reading Drupal Tip: Lightbox pop-up on page load

Drupal and its serious e-commerce muscle

It has been about a month since my last post, but the site is getting some real nice traffic since the posts about my “Drobo Alternative“. So thank you all for the support.

I’ve been working my rear off these days… apart from my day job I am working on two other sites. Both are e-commerce oriented sites based on Drupal.
While Drupal may not be particularly popular among e-commerce ventures, I am here to tell you that it has some serious e-com muscle and potential.

The particular module is called Ubercart. It is a full featured e-commerce Drupal module that handles the frontend store, as well as inventory and payment processing. What is even more important is that since this is a Drupal module, it can take advantage of the various existing Drupal modules to function. Thus, allowing the developers to make Ubercart great at what it does.

The folks over at TopNotchThemes developed an amazing sample theme that supports Ubercart out of the box. This is the Acquia Prosper. I use as a foundation for all of my Drupal e-commerce projects. It is built on the Fusion themeing framework and highly customizable.

All you need to do is download and install these on your box… hook it up with a PayPal account and you are good to go.

Coming from OScommerce, developing on Drupal is much more organized as long as you stay within the scope of the Drupal API. The API is comprehensive but it is quite the beast to master. It is nothing like writing your normal PHP app, and it makes you feel like you are developing in another language.

Having said that, Drupal + Ubercart is years ahead of OScommerce in every way. I love the modular design that makes Drupal what it is, and the enormous dev support i has behind it.

I’m going to try and write my magazine subscription app as a Ubercart add-on this summer.

finding the perfect Virtual Private Server (VPS)

I’ve been searching for a cheap VPS for some of the projects I’m working on. I needed an affordable plan… (by that I mean CHEAP! <$20) with great stability and reasonable support.

This sounds almost impossible to pull off… even in today’s world. Most popular shared plans cost more than $20…

But wait, introducing Unmanaged VPS service.

An unmanaged VPS is basically an empty VPS space with a metred uplink. The hosting companies will not install ANY software for you… no Apache, no MySQL… no PHP. You must do all the work yourself. Their job is keeping the physical servers and their uplinks online. (Previously I worked remotely for a web hosting firm… so I know a fair bit about keeping things running.)

Before choosing a hosting company, you must understand some of the terminologies used to value VPS packages.

CPU Speed/Limit: some hosts will give you an estimate of CPU in megahertz; obviously the higher number the faster. However, as a user you do not really have any practical way of measuring performance by looking these numbers… so I wouldn’t worry too much about it. Other hosts will specify if multiple CPU instances are allowed on the VPS to create a virtual multi-core space. These options are probably very expensive. Choose wisely according to your budget.

RAM: like the RAM in your computer, RAM on your VPS will be a great limiting factor of performance. The OS, Apache, MySQL, PHP instances all require quite a bit of RAM to run. I would say that 128MB is the absolute minimum you should have. I would recommend getting at least 256MB… because after I installed everything on my VPS… it was eating up more than 200mb while idling. I seriously would not recommend running production sites on a 128MB VPS.

Burst RAM: since resources on the physical server are still shared among multiple users, each VPS instance will have a guaranteed RAM size and a burst or peak size. The burst RAM specifies the maximum amount of RAM the VPS is allowed to allocate should the resources be available. You will see companies advertise their plans as 512MB RAM/1024MB Burst. This indicates that your VPS will get 512MB in any situation, and it is allowed to go up to 1024MB or 1GB when it is under load and the other VPS spaces on your server can spare you a few MB of RAM.

Continue reading finding the perfect Virtual Private Server (VPS)

installing APC & uploadprogress on CentOS 5 [updated]

First, we need the pecl command so we can download and install APC from the repositories. I use the “remi” repo to give me the latest packages, so use “–enablerepo=remi” if you have it installed.

yum install php-pear
But, this will not run on its own, we need the following package for the phpize command:

yum install php-devel
We also need the apxs command, which is installed via the following package:

yum install httpd-devel
Now we have all the software we need, so we install apc via the pecl command:

pecl install apc

I also recommend installing uploadprogress, because Drupal 6 will ask you to do so.

pecl install uploadprogress

Now we have to enable apc and uploadprogress in php.ini.

Add the following lines to /etc/php.ini or wherever your php config file is located.

Then we restart Apache:

/etc/init.d/httpd start
And we are all done. Watch for less execution time per page, and decreased memory usage per Apache process compared to what you had

include PHP inside custom Drupal modules


In an attempt to make my sites more dynamic and easier to manage, I use PHP includes quite extensively. I like the idea of make a change in a single file and have it propagated to other sections of the site that call upon it.

However, when you want to have multiple custom modules in Drupal to include PHP… it gets tricky. Depending on how your modules are written, it is usually not within the same scope as the Drupal core… therefore your variables should be global if you want to call them throughout the site.


include_once() and  require_once() do not work so well in these situations.

I’ll give you an example. I have written a very large and complex custom theme for a client with ecommerce needs. I’m including a file called that defines a bunch of variables for my ecommerce module. This file has been included in numerous modules with include_once().

I’m also using a module called node_content themehook to theme only on a node level.

When I try to include in my node_content templates using the *_once() functions… Drupal thinks the file has been included once even when it has not. This problem is not specific to the node_content module. When you have multiple modules calling the same file… using *_once() is not reliable at all.

The solution…? simple as hell.  Use include() and  require().

New projects…

busy busy busy…

Got another Drupal project booked… this time I’ll be using UberCart instead of OsCommerce. UberCart is a native Drupal module that offers comprehensive e-commerce features to the platform. UberCart does require some effort to configure and it really doesn’t work straight out of the box (unlike OsCommerce) but it takes full advantage of all the common Drupal goodies – CCK, View, taxonomy… Check back for more updates, and I’ll be posting my codes as the project moves on.

Previous employer (Alternatives Journal) is teaming up with Magazine Canada and to offer digital magazines. This will probably make my custom OsCommerce platform obsolete… but it’ll be interesting to learn how Zinio operates. Zinio is giving these magazines a very sweet deal and I was surprised to learn that most of their services are free (for the duration of the contract – 2 years).

I got the feel that they are trying to suck in as many clients as possible by offering free incentives to publishers and customers. However, a glance at their UI left me with much to desire. I didn’t see any innovative features at all… at the end it just felt like another Flashpaper viewer with embedded PDFs. When compared to more polished services like,  Zinio has some work to do.

I still haven’t seen any paperwork from Zinio, but the challenge will be to mesh our existing e-commerce effort with their system. Customer databases need to be synced… financial reports need to be combined and analyzed…. all the fun stuff.  Expect more updates.

Take a look at the site I built for Alternatives Journal – (Drupal site)