Tag Archives: Programming

Performance overhead of using plugins and includes in WordPress

Modularity requires additional overhead.  That’s just the way it is.  If you want to semantically separate different components of your web app or theme, you have to include files, run safety checks (e.g., include_once), extend components that you only use 20% of, etc.

WordPress encourages this behaviour, if you have plugins that only effect your admin panel, the files still get included and the actions and filters still get included, the functions are still defined, for every frontend visitor page render — but they are only called into action when you’re on the backend of your site.

And lately when coding for WordPress, I’ve come to embrace and accept that it wants me to be modular and extend.   Continue reading Performance overhead of using plugins and includes in WordPress

Advertisements

Starting and stopping NginX-MySQL-PHP-FCGI on Mac OS X

As these things go, it’s super easy to get a LEMP stack up and running on Mac OS X 10.6 (Snow Leopard).  Although at that point I guess it’s a MNMP stack, but that’s an even more ridiculous mnemonic.

Starting up and shutting down each individual service, however, is a pain in the butt.  Sure, 3 services doesn’t sound like a lot now but wait until your 12th configuration tweak in the course of a few hours.  Sure, every tutorial out there has a copy-and-paste-service-script-that-only-needs-a-few-tweaks-to-get-up-and-running-on-your-system.  Forget that; I just want to sudo port install nginx mysql-server php-fcgi and rock’n’roll, bitch.

I don’t want these things running all the time, so forget setting them as startup items.  And I don’t really have the patience to make or tweak service scripts.

So here’s what I do

Helper class for Zend Framework apps

Maybe it’s because I got my ZF start from Magento, but I’m enamoured with having a static class full of global helper methods.

For example:

/**
* Get the user's real IP address through proxies
*
* @return string
*/
public static function getIpAddress() {
    // Gets the user's real IP address
    if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
        $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        return trim($ips[count($ips) - 1]);
    } elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) {
        return $_SERVER['HTTP_CLIENT_IP'];
    }
    return $_SERVER['REMOTE_ADDR'];
}

Implementation and more examples behind the cut

Case-insensitive module URLs in Zend Framework routes

I started creating modules for my application using the CamelCase module names, as I interpreted the standard ZF syntax (ex. /path/to/app/root/application/modules/User/controllers/).  Then I realised this made my urls case-sensitive as well (ex., http://www.example.com/User/).

Uppercase/CamelCase module names still make more sense to me, since the class names inherit the case.  If I used lowercase module names (ex., modules/user/) then my classnames would also be lowercase (ex., user_Model_Name) which really seems funny to me.

So I opted to make a front controller plugin to handle the conversion for me, thus making module names in the URL inherently case-insensitive.   Continue reading Case-insensitive module URLs in Zend Framework routes

MySQL error: Manager of pid-file quit without updating file.

So I was working at home over the weekend using MySQL on my MacBook running OS X 10.6 (Snow Leopard), put my computer to sleep then came in to the office this morning and opened it back up.

At one point I had to restart MySQL (which up to this point was running fine), and received this error:

$ sudo /opt/local/share/mysql5/mysql/mysql.server start
Starting MySQL
.................................................................
ERROR! Manager of pid-file quit without updating file.

Continue reading MySQL error: Manager of pid-file quit without updating file.