MySQL AB aquired by Sun

Big news in the database world today, MySQL announced that they have been aquired by Sun Microsystems.  Was a bit of surprising move to me as last I heard was the rumors around looking into an IPO.  Of course by no means am I up-to-date or an industry insider.  I’m not sure yet how I feel about this move.  Its probably a good move for Sun, but how is it going to affect the LAMP world?

According to Kaj Arno it will be a good thing due to Sun’s already strong presence in the open source world citing references to Java and Open Office.  I agree that Sun’s open source initiatives are a good thing (it could have been Oracle /shudder).  However, I don’t like Java and I don’t like Open Office.  I also think the audience that uses Java and MySQL might be somewhat different from the larger LAMP sites like Facebook and Yahoo!.

I suppose only time will tell.  Its probably just the db geek in me, but I’ll be watching this closely over the coming months.

Posted under mysql

This post was written by Michael Tougeron on January 16, 2008

Tags: , ,

last night’s geekSessions 1.3

Last night’s geekSession as pretty interesting. The panel of PHP superstars knew their stuff (of course) and gave a high level 15 minute talk. For some reason I always enjoy watching when panelist debate back and forth over what the best approach is. Like when Lucas @ Facebook.com was talking about a few milliseconds of speed and Sara Golemon @ Yahoo! said it didn’t matter. :P All in good humor and it highlights that there are many solutions to the same problem. Some may work and be essential for one company and not make a difference for others. Facebook does get a shit load of traffic so they’re always looking to get that extra little bit out of things.

It was nice to meet Cal Henderson, I love his book about site scalability “Building Scalable Web Sites: Building, scaling, and optimizing the next generation of web applications” I highly recommend buying it if you haven’t already. Of course I didn’t want to be a groupie or anything so I didn’t tell him that. Wanted to though. :P

I didn’t get an opportunity to talk with Andrei; I didn’t recognize him (stupid eyes) and it was too noisy to really hear his introduction. I a bit too shy to try to re-introduce myself.

Surprisingly Terry Chay was quite quiet. Didn’t stop the speakers from cussing for him. Really glad he introduced me to Lucas though. That was a big help.

Speaking of Lucas, he’s working on a new talk and wants to try it out before going to the conferences with it. He’s thinking about bringing it to the PHP Meetup in the next couple of months to see how it goes. I hope that happens, bringing more well known PHP names to the group will help take it to the next level.

Posted under Events, PHP

This post was written by Michael Tougeron on January 16, 2008

Tags: ,

memcached PHP semaphore & cache expiration handling

There are a lot of different ways that people use memcached and PHP. The most common of which is probably your basic set and get to cache data from your database.

  1. function get_my_data1() {
  2.     $cache_id = "mykey";
  3.     $data = $memcache_obj->get($cache_id);
  4.     if ( !$data ) {
  5.         $data = get_data_from_db_function();
  6.         $memcache_obj->set($cache_id, $data, $sec_to_cache_for);
  7.     }
  8.     return $data;
  9. }

But what if the query that’s going to hit the database is pretty intensive and you don’t want more than one user to hit the db at a time? That’s easily handling via a semaphore lock.

  1. function get_my_data2() {
  2.     $cache_id = "mykey";
  3.     $data = $memcache_obj->get($cache_id);
  4.     if ( !$data ) {
  5.         // check to see if someone has already set the lock
  6.         $data_lock = $memcache_obj->get($cache_id . ‘_qry_lock’);
  7.         if ( $data_lock ) {
  8.             $lock_counter = 0;
  9.             // loop until you find that the lock has been released.  that implies that the query has finished
  10.             do while ( $data_lock ) {
  11.                 // you may only want to wait for a specified period of time.
  12.                 // one second is usually sufficient since your goal is to always have sub-second response time
  13.                 // if you query takes more than 1 second, you should consider "warming" your cached data via a cron job
  14.                 if ( $lock_counter > $max_time_to_wait ) {
  15.                     $lock_failed = true;
  16.                     break;
  17.                 }
  18.                 // you really want this to be a fraction of a second so the user waits as little as possible
  19.                 // for the simplicity of example, I’m using the sleep function.
  20.                 sleep(1);
  21.                 $data_lock = $memcache_obj->get($cache_id . ‘_qry_lock’);
  22.             }
  23.             // if the loop is completed, that either means the user waited for too long
  24.             // or that the lock has been removed.  try to get the cached data again; it should exist now
  25.             $data = $memcache_obj->get($cache_id);
  26.             if ( $data ) {
  27.                 return $data;
  28.             }
  29.         }
  30.         // set a lock for 2 seconds
  31.         $memcache_obj->set($cache_id . ‘_qry_lock’, true, 2);
  32.         $data = get_data_from_db_function();
  33.         $memcache_obj->set($cache_id, $data, $sec_to_cache_for);
  34.         // don’t forget to remove the lock
  35.         $memcache_obj->delete($cache_id . ‘_qry_lock’);
  36.     }
  37.     return $data;
  38. }

More below the break –> Read More…

Posted under PHP, Tips & Tricks, Web Development, mysql

This post was written by Michael Tougeron on January 11, 2008

Tags: , ,

MySQL Meetup tonight @ 6pm

The MySQL meetup is tonight at 6pm here at CNET. Not much of an official topic tonight. It’ll be more of an informal discussion about a lot of different things. I think I’d like to talk about community based db schema. Maybe forums or tagging or whatever. Anyway, if you’re a MySQL db buff, you should come, they’re a lot of fun. Food, beverage, nice people, what else could one ask for? They’re the first Monday of every month. Check it out if you’re in the neighborhood: http://mysql.meetup.com/30/calendar/6851629/

Posted under Events, mysql

This post was written by Michael Tougeron on January 7, 2008

Truck got rear-ended Sunday

My wife was in a pretty big auto accident yesterday. She got rear-ended by some old lady who wasn’t paying attention to what she was doing. How do you miss the line of stopped cars at a stoplight when the street is only a block long? Not only was she acting weird, driving without identification or insurance paperwork, but she also lied to the police a couple of times. The police had to wait on DMV results because they thought she was misleading them with who she was. Unfortunately she passed a breathalyzer test so the cop couldn’t arrest her. He did say she seemed like she was on something, but he could tell what so he couldn’t arrest her.

The scariest part of all this is that my wife is only 17 weeks pregnant. Those seatbelts against the stomach can be very dangerous for pregnant women. We ended up spending 5 or 6 hours in the hospital while they ran a series of tests. What a nightmare.

My truck seems pretty toast to me, but hopefully they’ll be able to just replace the bed of it and go from there. But the whole rear and left side are packed in, dented, scraped, and just all around jacked up. Even though it bent the pipe where the gas goes in, no gas leaked (thank god).

Was not a fun Sunday afternoon. :(

Posted under Events

This post was written by Michael Tougeron on January 7, 2008

Tags: ,