It's as efficient as you can possibly get with PHP .. how is that ugly? Ugly because it doesn't remind you of Python, Ruby or whichever language you prefer?
Nothing wrong with that attitude at all! Especially when backed up with code. Keep up the good fight .. but I would suggest you implement this as an extension.
Yeah, I think that'll be the way to go. There's apparently a new way of writing extensions, might've gotten slightly more bearable since you last looked at it :)