Tag Archives: php

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.

Self-Updating Code in WordPress

One of the problems I face when having to deploy new code changes — especially those that require database changes, such as updating options, activating or de-activating plugins, etc — is the lag between deploying the code and making the relevant changes to the database. We can’t really risk the site looking broken for even the shortest time, especially true if the broken page gets cached.

Enter the need for self-updating code. The code will “activate” itself the first time it’s run — no temporary glitches in viewing the website because code is live but db changes aren’t or vise-versa.

Continue reading Self-Updating Code in WordPress