Tag Archive for 'PHP'

Server Logs: when XML and PHP have sex

My homey Chad has introduced me to the usage of XML. At first, I really didn’t know much about it besides the fact RSS feeds use it. But now the more I learn the more I love it.

When we wrote the logs for Gear, we had a couple of choices. We could bloat a MySQL database with tons of log events, write it all to a flat file, or devise something new. Which chose the latter and our answer was XML. With the ability to store attributes and content, have parents and all sorts of hierarchy… its easily one of the best decisions we’ve made.

But when we get back to the topic of having the website and game servers talk, we run into a hiccup. All our events are stored in different sub tables; which means the log has a tables like <chatlog> and <eventlog>. Yeah that’s all fine and dandy, and we love how it turned out… but what happens when people want to view said logs? They aren’t shuffled together in chronological order… they’re all separate. SHIT FUCK DAMN!

Putting them together in order wasn’t as easy as it should have been. Well actually I’m lying; it was easy once I figured out how to do it. That’s the thing about programming/scripting/developing custom shit: its not that the syntax or platform limits your ability to do something, or that it requires butt-loads of work… its being creative enough to figure out how to fucking do it. WHRY?!? Because not everything you want to do has been done by someone else in easy copypasta format.

Server LogsWhen I started working on it I was looking for some PHP command that automagically did it for me, and I think that was my problem. When trolling the PHP manual website and furiously searching Google for “put my XML in order” was no help, I decided to do it on my own.

Basically it came down to putting all the data into an array, and then sorting said array with the usort function. SUCCESS!

The only thing left was to display the data in a readable format. So mix in a tad of HTML, add a pinch of CSS… blend until sexy and you’ve got a finished product!

Writing a CMS

*** Preface: For those who want to further read about what a CMS is click here

A content management system (CMS) is a computer application used to create, edit, manage, and publish content in a consistently organized fashion

So the last website design I cooked up was pretty neat, but I’m remaking it (see my previous post to understand why). The other thing I’m focusing on is the script that drives the site. Last time it was a rudimentary PHP script that just spit out content. This time I’ve taken a step back and decided to do it RIGHT.

I’m going to write it myself from the ground up. Its easy enough to go with some prepackaged script some nerds put together, but then I’ll end up hacking the shit out of it to make it do what I want… so whats the point in using it in the first place? The other reason to write this myself is because the website interacts with the game server so much; I want to make sure I have as much control over this as possible.

Here’s some cool things I’ve learned that you should all use at one point or another in a PHP script:

  • Classes. Use classes or you’re and idiot. Object orientated programming is your friend.
  • ob_start… look this function up and harness its power.
  • Just like any application, make your web applications modular. God kicks a puppy in the face every time you don’t.
  • Comment your code. Even if you’re the only person that’s ever going to look at it, it helps you debug and sometimes even reminds you what the fuck you were thinking.

I don’t think I’ll make a template system. I’ll just make a hybrid index.php that renders the basic site layout and calls functions to display content. I’ve tossed around the idea of making templates, but I think its a waste of time for what my needs are.

I’m still working on the new site design… I’m getting closer. One step closer I guess, but now I’m off to play some Xbox 360.