The random rantings of a concerned programmer.

(Untitled)

March 14th, 2009 | Category: Random

hahaha, I fucking hate PHP.

But I finally got a Meimei instance running on someone else’s machine. God, there are so many fucking differences between PHP installs. It’s bloody ridiculous. The damn thing worked fine on my Dreamhost account last weekend, but they’re running Apache with mod_php (I think?). It looks like the guy who put this instance up is running Lighttpd (and possibly a different minor version of PHP).

And it doesn’t help that the language is such a fucking mess. There were a couple of really stupid fucking mistakes (res instead of ret) that would have been caught at compile time by a real language rather than this toy. Maybe I’ve just been pampered too much?

On the work front, we’ve got 5 days to put together a mobile version of our main web site (in PHP, of course — how the fuck did I turn into a fucking PHP web developer). God that shit’s pretty fucking bad; at least it’s easy “lol let’s generate sum html codez” rather than Meimei which is batshit insane from any perspective.

Goddamn I need another drink.

8 comments

(Untitled)

March 01st, 2009 | Category: Random

So I came up with a brilliant solution to bandwidth/disk rape — write a small PHP script (Meimei) which caches images from 4scrape (Suigintou), give it out to people, and just randomly direct people to those mirrors with javascript. Validation issues aside (“oh hey let’s just serve lemonparty for every image”) — because those can be “fixed” by only allowing trusted mirrors — I don’t think it’s going to work.

I threw up a test version of the script on my DreamHost account and it completely shit itself. It worked for a while, then it started spewing 503 errors everywhere. I don’t know if this is an issue with DreamHost or my shitty code (or the fact that by putting it up to serve 100% of the requests, it was bombarded with almost 1000 hits in the few minutes that it was up), but it definitely needs a lot more tweaking before it’s usable. It’s one of those “ugh PHP” things and it’s just a bitch.

The version I have running right now is really stupid — it basically just acts as a caching HTTP proxy. To have the thing fully functional, it needs to do a lot more than just that (and the server stuff on Suigintou needs to be a bit more sophisticated too). Each Meimei instance needs to track how much bandwidth it’s used (it already tracks disk consumption); it needs a means to communicate back to Suigintou that it’s all filled up or out of bandwidth or whatever.

There also needs to be something which gives some notion of cache locality — ie, a Meimei might say “I only want images in the range 30000-40000 that are SFW and from /wg/”. That way it’ll consistently get handed those requests and hopefully hit the cache more often (though eventually, assuming unlimited disk, each Meimei instance will be a full mirror — this isn’t a sound assumption).

And then you hit mirror validation. I’d want to do in a distributed manner with JavaScript, ie, check the MD5 of a subset of the image data against a known value from the authoritative Suigintou, then report back to Suigintou if the mirror is giving bad data and not display the image. I don’t even know if that’s going to be possible in a realistic manner, or how evadable my checks would be. I think if there aren’t more than 5-7 Meimei instances they’ll either get overloaded with requests, not be clustered enough to achieve decent locality, or just be otherwise ineffective at staving off bandwidth consumption.

Would be nice to have it all working and shit but ugh it’s almost too much work. Bleh.

6 comments

(Untitled)

February 12th, 2009 | Category: Random

Oh man Katsucon is tomorrow — going to be a royal shitfest.

Anyway so I’m rewriting one of our websites in PHP (with Drupal). PHP is a pile of shit, but honestly if I were to write the thing in Haskell no one would be able to maintain it. And PHP is a big step up from what it’s currently written in — ColdFusion.

I had written a couple of little widgets in ColdFusion to pull feeds from a couple databases for shit, and I wanted to port those over to my Drupal installation. So I poke around in the ColdFusion code looking for it, and wtf my code isn’t there — it’s just static HTML once again (in the past, the “feeds” have always been updated by hand). A quick look in the svn log –

————————————————————————
r3717 | Coworker_A | 2009-01-29 10:42:50 -0500 (Thu, 29 Jan 2009) | 1 line

manually updating “Classes” section; Taro’s dynamic piece is not ready–Coworker_B needs to do a ColdFusion piece to go with it
————————————————————————
r3716 | Taro | 2009-01-29 10:30:27 -0500 (Thu, 29 Jan 2009) | 2 lines

Changed upcoming classes on the index page to dynamically pull the first three upcoming events from the database and display them on the page.

The “ColdFusion piece to go with it” wasn’t so much a piece as it was “please refactor I suck at ColdFusion”. The thing worked perfectly fine, and he just bloody wiped it out and replaced it with static HTML (the exact same HTML that the widget generated). So now I’m sitting around waiting for the checkout of revision 3716 to complete because I was too lazy to look up how to pull a single file from the repo to reference the code.

RAAAAAAGGGGGEEEEE

No comments

(Untitled)

January 16th, 2009 | Category: Random

Blarg, WordPress. I think I’ve got everything hacked up and working (and I fixed the database that I dicked up — just had to poke around a little bit more). Honestly though, I’m not impressed at all with the code quality of WordPress µ — there’s a lot of stupid code:

# Strip ports out of domain, but only on 80 or 443
if( strpos( $domain, ':' ) ) {
    if( substr( $domain, -3 ) == ':80' ) {
        $domain = substr( $domain, 0, -3 );
        $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
    } elseif( substr( $domain, -4 ) == ':443' ) {
        $domain = substr( $domain, 0, -4 );
        $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
    } else {
        die( 'WPMU only works without the port number in the URL.' );
    }
}

# Strip ports out... AGAIN? This can't actually be reached.
$domain = preg_replace('/:.*$/', '', $domain);

It’s really kind of retarded — there’s dead code paths all over the place and shit. And this is just the WPMU code which (effectively) wraps the WordPress code (which itself is pretty bad too). I guess that’s just the current state of lol PHP applications.

On another point, WPMU has two “modes” by which it can branch — you can either use subdomains or subdirectories to select which blog to view, ie

  • user.domain.com
  • domain.com/user

And that’s fine and all, but choosing one or the other just doesn’t work in our case — we want new users to have a directory-branched URL, but there are already some blogs in the system that have separate domains. Obvious fix is obvious –

if ($_SERVER['HTTP_HOST'] != MAIN_HOST) {
    define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
    define('VHOST', 'yes');
}
else {
    define('VHOST', 'no');
}

hurr durr. Honestly I’m amazed that such large sites (ie, WordPress.com) can possibly run on such shitty code.

2 comments