| By Ian Selby | Article Rating: |
|
| June 9, 2008 11:00 AM EDT | Reads: |
7,940 |
Ian Selby's Gen X Design BlogNothing's cooler than writing a bad-ass site or application and watching it gain popularity and a significant user base. By the same token, nothing's more frustrating than watching your app fall on its face when its running under high load. If you're like me, you know how disheartening this can be, as it usually means that it's time for a hard dose of reality: your code probably isn't as awesome as you thought it was.

Or is it? There’s a whole slew of things that a person could point a finger at regarding slowly running code. The most-oft thing that gets called out is code with a lot of overhead (a ton of includes, excessive logic, and the like), and right behind that is poorly designed databases (unoptimized indexes, no indexes, ridiculous amounts of joins, blah, blah, blah). Well, let’s assume for a minute that you’ve got a fair amount of experience under your belt, so you know your code is pretty damn optimal, and you also have a DBA buddy that took a look at your database and helped you tweak it up a bit. What do you do if this isn’t enough? Before you say, “throw more / better hardware at that mo-fo”, why not take a moment and learn about APC: Alternative PHP Cache…
OK, as usual, let’s make sure we are aware of a few general understandings before we get into the goodness of APC. It is very important to understand that despite all your optimization work, you’re always going to run into two major hurdles when it comes to keeping your app running blazing fast… that’s just the way it is. True, there’s a lot of things I’m glazing over here, and there’s even more points that could be debated… if you want to talk about it, feel free to contact me, I love talking code. For the sake of brevity and clarity, however, we’re going to steer clear of the nitty-gritty and look at things in a much broader scope. So, anyway, those two hurdles: memory, and database bottle-necking. You’re always going to need more memory, and at some point, your database is going to be slowing your app down. But before you get ready to get that beefier server, or a separate database server, or anything else (as much fun as new toys can be), let’s take a look at what can be done with your existing hardware and code.
I think it’s a fair statement that a lot of applications retrieve the same information from a database over, and over again, and that it’s also safe to say that this information gets updated at predictable intervals. Wouldn’t it be nice if we could store this data somewhere so we don’t have to keep pinging the database over and over for the same thing? It would also be pretty cool if we could leave that data stored, and update it not only in the database, but in the “storage area” as well? Good news kids, you can certainly do that… all with the magic of caching… APC caching!
I’m going to show you how APC can be leveraged to cache your application data, thus eliminating a ton of repetitive trips to the database, and thus removing your bottleneck! As an added bonus, I’m also going to do my best to explain some of the other goodness of APC and caching in general, as a lot of the articles floating around the web assume you simply understand what “opcode caching” and other stuff like that means (I certainly didn’t for a while).
Hopefully, if you’ve written an app that would benefit greatly from APC, you understand how PHP works. If you don’t, here’s a quick review… PHP is an interpreted language, which means that the code you write isn’t actually compiled, like actual application code is. The PHP code you write is compiled at the time it’s requested, and it’s compiled every time. Obviously, this is a really fast process, but I’m sure you can see how it’s also problematic. Well, that’s why APC was developed (by one of the guys that developed PHP, in fact). APC keeps that PHP code you’ve written compiled in memory, or caches it. This is what an opcode cache is, nothing more than a cache of pre-compiled code. By simply installing APC and enabling it, you will probably see a noticeable speed improvement in your app. But there’s a lot more we can do with APC to speed up an app, and we’ll get to that shortly, but I think I need to answer a more pressing question: “How the hell do I get and install APC?”
Published June 9, 2008 Reads 7,940
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
- Xaja - An Open Source PHP Reverse AJAX Framework
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- Rolling Your Own MVC Framework - Starting-Point for Any PHP Application
- Sun Microsystems and NetBeans Community Extend Reach to Scripting Community with NetBeans IDE Early Access for PHP
About Ian Selby
Ian Selby is owner of Gen X Design. He has been developing web sites professionally for over 7 years, and has always tried to stay on the cutting edge of web trends and technologies. He believes that usability and the user experience are the most important thing when writing web applications. He has a passion for all things Web 2.0, loves shiny icons and gradients, and lives in the San Francisco Bay area. He works for Aptana.
- Ulitzer’s Amazing First 30 Days in Public Beta
- Will Ulitzer Dominate News Content on The Web? -Gartner
- Software AG Named "Gold Sponsor" of SOA World Conference & Expo 2009 East
- Open Source Java Guru Moving to Joost
- Ulitzer vs. Ning - a Quick Review
- Did Bill O'Reilly and Fox News Contribute to Dr. Tiller's Murder?
- Dell Trades Up to Nehalem
- Ted Weissman and Lois Paul & Partners PR Firm
- Sony Trademarks the Term ‘PS Cloud’
- New Adobe Video Component for Flex
- Ulitzer’s Amazing First 30 Days in Public Beta
- Will Ulitzer Dominate News Content on The Web? -Gartner
- Nokia E71 Black Review
- Software AG Named "Gold Sponsor" of SOA World Conference & Expo 2009 East
- Open Source Java Guru Moving to Joost
- Intel and Adobe Putting Flash on TV
- Hitachi Chooses Canesta's 3D Sensor Chip to Power New Gesture Controlled TV
- Ulitzer vs. Ning - a Quick Review
- Did Bill O'Reilly and Fox News Contribute to Dr. Tiller's Murder?
- Dell Trades Up to Nehalem
- Video Conference with Flex & FMS
- SYS-CON Events Announces iTVcon Internet TV Conference & Expo 2007
- iTVCon - Internet Video Conference & Expo Registrations Now Open
- Internet Video Update: First "Webisode" of Quarterlife Will Air on MySpaceTV
- "TV Anywhere, Anytime" Gets a Boost...From Joost
- Microsoft's Flash-Killer Silverlight Streaming Video Plug-in Released
- Android: Who Hates Google Over the Phone?
- iTVCon - Starts Next Monday! Check Out the Full Speaker Lineup
- From Enterprise to Cloud, Virtualization Today on SYS-CON.TV
- Virtualization: "The Leading Technology of the 21st Century"







































