April SF PHP Meetup – symfony

Wow, I just realized how long it has been since I last posted here. It has been a crazy few weeks. Everything from setting up the baby furniture to fixing my rental condo, taxes to layoffs at CNET and more. I’m beat.

Anway to the topic at hand…

April’s PHP Meetup is looking like it will have another great turn out. The group just keeps growing and growing. Our average attendance for the last two months have been over 70 people! I still have a hard time believing that this many shy, techie geeks like me actually show up. :P

April’s topic will be run by Dustin Whittle from Yahoo! and will be about the symfony framework. He’ll be doing a brief overview of the framework and then walk people through setting up a site. If you’re planning on attending, bring your laptop and code along with us.

Posted under Events, PHP, Web Development

This post was written by Michael Tougeron on March 28, 2008

Tags: , ,

Feb 2008 PHP Meetup – Terry Chay: OOps! The PHP Fear and Loathing Guide to OO Design

We have a topic now for February’s PHP Meetup thanks to Terry Chay.  He’s going to clean up and update a talk he has on object-orientated PHP programming and give it to the group on Feb 7th.

Terry has had a strong presence in the last couple of meetups; they probably wouldn’t have been successes without him.  This talk should be pretty interesting and should draw a good sized crowd.

On a side note, what’s up with meetup.com lately and their email system?  It used to be I’d email the group and it’d arrive in my inbox a few minutes later.  Still nothing.  Weird.

Posted under Events, PHP, Web Development

This post was written by Michael Tougeron on January 18, 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 mysql, PHP, Tips & Tricks, Web Development

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

Tags: , ,