Pligg now runs on Quercus
Friday, October 31st, 2008Over the last week, I had the pleasure of trying to get Pligg, a PHP content management system (CMS), to run on Quercus. It wasn’t easy due to a diabolical bug (more on that later), but it’s resolved for our upcoming 3.2.2 release and Pligg should run pretty swell.
So why another CMS? Quercus can already run Wordpress and Drupal, arguably the heavyweights in the PHP CMS arena. Well one of our good Resin users has over 50 Pligg sites and he wanted to migrate to Quercus. He had observed that PHP was being overloaded to such a point that all the linux swap space was being used up. So Quercus’ performance is very appealing to him. Checking my emails, it appears that he has been trying to run Pligg on Quercus for over a year :0. Talk about persistence and commitment!
The thing preventing him from running Pligg was that Pligg was reusing variables inside functions and declaring them global later on:
$a = "initial";
function test()
{
$a = "changed";
...
global $a;
//$a here on out should be "initial"
...
}
Quercus is highly optimized and has optimizations for variables. If it sees the global statement inside a function scope, Quercus assumes that variable is global throughout the function. The issue was that any modifications to that variable was modifying it globally, when it should be modifying it locally, until the global statement is reached of course.
The question is: why would Pligg be reusing variable names and changing their scope? Why not use a different name? Why not put the global statement at the beginning of the function?
Sifting through their code, it appears that they eagerly initialize a copy of config objects. They do so by using includes. The includes store the results in a specific variable. So if you don’t want the includes to modify the global variable, then you better not have the global statement before these includes. We would never expect this, hence the Quercus bug. This is an example of unorthodox coding that PHP permits that we see all the time and it’s what makes it extremely difficult when we debug PHP applications.
