Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Dave Marshall's Blog:
Defending against Cache Stampedes
Jan 13, 2012 @ 19:13:08

Dave Marshall has a new post to his blog showing one method for defending against cache stampedes from assaulting your caching servers and (possibly) bringing them down.

I’ve recently had a problem with a rather large operation (that could probably be optimised considerably, but nevermind), where by if the cached result of the operation expired, several web server threads would attempt the operation, causing some major headaches for our database and web servers. This is something I’ve come across before, and is commonly(?) known as a Cache Stampede. This is bad, this post describes the basics of what I’ve done to deal with it.

His example uses a Zend_Cache interface to Memecache, but it could be applied in other places too. His method uses a binary semaphore to check and see if there's a "lock" and sleep for a bit before checking again. Sample code is included showing how to create this system and how to refresh the data with a new expiration on a cache miss.

tagged: cache stampede zendcache tutorial binary semaphore miss prevention

Link:

PHPBuilder.com:
Boost PHP Site Performance with Zend Framework Data Caching
Dec 02, 2010 @ 16:36:55

New on PHPBuilder.com there's a tutorial from Jason Gilmore looking at caching data with Zend_Cache, a component of the popular Zend Framework. He focuses on how it can boost the speed and overall performance of your application (even if you don't use the Zend Framework!)

Zend_Cache can be configured to cache several types of output, including the results of function calls, the results of object and static method calls, entire pages, and configuration data. You determine what data is cached using Zend_Cache's frontend. This data can be cached in several ways, including using system memory (RAM), using memcached, within text files, or within a SQLite database. You determine exactly how your data is cached using Zend_Cache's backend.

His examples use the Zend_Cache component on its own, so you don't have to wade through other Zend Framework-ish code to pick out just the parts you need. He implements file-based caching and shows how to set up both the frontend and backend options to make it all cooperate.

tagged: zendcache zendframework component tutorial file cache

Link:

PurpleRockScissors.com:
Avoiding Cache Stampedes with Pseudo-Locks
Oct 22, 2010 @ 16:14:25

In this quick post to the Purple Rock Scissors blog, there's a suggestion from Rob Zienert about how you can avoid a "cache stampede" on your site's caching tool with the help of a pseudo-lock on the record.

A cache stampede occurs when a cached item expires and multiple clients attempt to repopulate the cache at the same time. Take for example a page cache expires and a few thousand people try to refresh the generated HTML. That's a lot of instant load — hitting the database, re-saving the cache and so-on: it's a lot of extra processing that can bring a website to its knees. One of the many ways to avoid this from happening is to apply pseudo-locks to a cache (and works great with Memcache).

He includes a code snippet example showing how to create the lock using a Zend_Cache setup by looking for a URI-based lock file and setting a "locked" value to true when someone else is using it.

tagged: lock cache memcache zendcache tutorial

Link:

phpRiot.com:
Zend Framework 101: Zend_Cache
May 13, 2010 @ 22:43:14

In another in his Zend Framework 101 series of articles on phpRiot.com Quentin Zervaas sets his sights on Zend_Cache in this new tutorial.

In this article I will introduce you to the Zend_Cache component of the Zend Framework. This component is used for improving the performance of your web application by saving generated data for later reuse. [...] While the idea behind caching is straightforward, there are certain considerations and complexities to be aware of. You need to consider the type of data you want to cache and the situations in which to use it.

He covers two of the main types of caching - caching bits of data as they're generated and and caching the end result of a whole HTML page. You'll need to have a copy of the Zend Framework up and working.

tagged: zendframework zendcache tutorial cache

Link:

Brandon Savage's Blog:
Caching For Efficiency With Zend Framework
Apr 05, 2010 @ 13:48:16

Brandon Savage has posted another in his series looking at useful tips for working with the Zend Framework. This time he focuses on caching your data to help improve its overall performance.

So, given this performance difference [between static pages and Zend Framework-driven pages], how do we improve the performance of Zend Framework while still retaining its functionality and ease-of-use? Well, we employ caching, of course! But not just any caching. One of the beauties of a read-heavy website, especially one that doesn’t change all that often, is that we have the ability to cache entire pages and serve them directly using our web server.

He shows how to use the Zend_Cache component to create a simple caching object tat allows you to cache the entire page contents and, with the help of a little mod_rewrite trickery, tell Apache how to grab them (or regenerate them if need be).

tagged: cache zendframework tutorial zendcache modrewrite

Link:

Adrian Schneider's Blog:
Caching Zend Framework Forms
Feb 11, 2010 @ 17:36:10

In a new post to his blog Adrian Schneider looks at a method for caching your forms in your Zend Framework application so you don't have to recreate it every time.

Generating a form is an expensive process in ZF. It’s always bugged me that I can’t find any resources on trying to cache the initial HTML anywhere, so I took a stab at it myself. I use a loader from inside my controller action to load forms and models, so I found that was a good place to start.

To help solve the problem, he's created a simple loader class (maybe dropped into an action helper) that, when used will cache the form (using Zend_Cache, of course) to keep the object instance where you can get to it later. The code to implement it and to put it to good use is also included.

tagged: cahe zendform zendframework zendcache tutorial

Link:

Joey Rivera's Blog:
Using Zend_Paginator with Twitter API and Zend_Cache
Jan 29, 2010 @ 16:54:44

In a recent post to his blog Joey Rivera looks at using the Zend_paginator component with Twitter and APC to create a cachable, paged view of a set of Twitter API results.

I'm going to focus more on Zend_Paginator and Zend_Rest_Client to access Twitters API since I've already created a post on Zend_Cache. Normally, I would use Zend_Service_Twitter to access the twitter service but it still seems to require authentication to retrieve a users timeline where only protected users should require authentication.

He includes all of the needed code including the bootstrap.ini file and his own custom Twitter service class that grabs the timeline of the given user and calls the REST interface to grab the latest posts and caches them to a file.

tagged: zendpaginator zendcache tutorial twitter api

Link:

Zend Developer Zone:
Enhance performance with Zend_Cache
Jan 08, 2010 @ 14:44:50

On the Zend Developer Zone there's a recent tutorial from Chris Renner focusing on the use of the Zend_Cache component of the Zend Framework to increase the performance of your site by caching chunks of data to easy retrieval.

The applications I develop and manage are very heavy with database transactions. Hitting the db every time you need an object is a serious performance bottleneck, and on a shared environment can be troubling to other applications living in the same environment. I'm going to describe my experiences with Zend_Cache here, but I am not going to bore you with lots of code detail and specifics.

He talks about the frontends you can use to cache the data to different types of formats, includes a code example for caching objects with the component and how to clear out the cache when you need to refresh the content.

tagged: zendcache performance zendframework tutorial

Link:

Joey Rivera's Blog:
Caching using PHP/Zend_Cache and MySQL
Nov 10, 2009 @ 20:47:40

New on his blog today Joey Rivera has posted this tutorial about using the Zend_Cache component of the Zend Framework to boost the performance of your site.

I like the definition used in Wikipedia: "a cache is a temporary storage area where often accessed data can be stored for quick access". The idea is to get 'often accessed data' from a database and store it in memory (RAM or as a file in your local file system). [...] Resources are limited on systems and to take advantage of your resources, you need to make sure time isn't spent on tasks that could be handled better elsewhere.

He talks about the Zend_Cache component and what sort of features it includes like the different caching methods (file, SQLite, mamcache, etc) and the different frontends your application can use (output caching, class caching, file caching, etc). He sets up a sample environment and shows how to cache a variable to a file, database results into a file, caching an entire page and how to clear out the cached items.

tagged: caching zendframework zendcache tutorial mysql

Link:

ZendCasts:
Using Zend_Cache to speed up Web Service calls
Sep 15, 2009 @ 17:07:16

On the ZendCasts site today there's a new video looking at the Zend_Cache component of the Zend Framework and how it can be used to speed up the response time for things like calls to a web service.

This is part 4 in a four part series on Google Docs and Google maps. While this example shows how to cache a Class to a file, you could easily modify the code to work with other caching backends such as a memory-based caching engine or something like Zend Optimizer or APC.

If you want to get caught up on the series, here's the links to part one, two and three.

tagged: zendcache zendframework webservice tutorial video

Link:


Trending Topics: