I know, I know. It has been over a month since my last post. Sadly, this graduate project of mine has been taking up all of my time.
Of course the time spent has not been a waste. In fact, it has been far from it. Part of the project involves users participating in a multiplayer trivia game done in Adobe Flash. The idea is that Flash will communicate with PHP via ZendAMF and PHP will talk to a C++ server via network packets. Since I haven’t written in C++ in ~3-4 years, it has taken me a bit to get back into the hang of things.
Things have changed since the last time I wrote in C++, especially because now I’m writing for a Linux OS, using direct network communication, and running in a threaded environment. I followed some people’s advice and started to look into the Boost Libraries. After about a week of frustration working with Boost.Thread and Boost.ASIO, I realized that everything I need to do can be done with pthread.h and sys/socket.h.
I noticed that most of my posts and projects have been quite centered around C# and application development instead of PHP and web development. To tell you the truth, I’m a little afraid of releasing my PHP code. Trust me, I write in true PHP 5 – very class oriented, none of this HTML intertwined between PHP code bull. It’s more that I want the code to be perfect before I release it. Starting now, I’ll try to share some useful functions I wrote that might help you on your quest to developing a PHP website.
Today, I’ll show you a quick function that converts time in words to seconds. Well, let’s say you are using memcached and you want to save an item for X seconds. It may be simple to put 60 for a minute or 3600 for a hour, but larger than that gets complex and not so easy to reverse (129600 is a day and a half). This function converts simple terms like “1d 6h” or “2h 24m 15s” to their seconds counterpart.