Bill Shupp Software engineer, photographer, musician, space geek

21Mar/110

Preparing your application for serving static content efficiently

(Reposted from the Empower Campaigns blog)

Most web applications have static content such as CSS, JS, images, etc.  To save on bandwidth costs and improve load times for your users, it's a good idea to tell the client to cache these items for a long period of time.  But even though your static content changes infrequently, when it does, the cached content needs to be invalidated.  In addition, high traffic sites often want to go a step further and take advantage of a CDN to offload static content delivery.  Below I'll share the method we used here at Empower Campaigns to accomplish both of these things.

Please follow and like us:
15Mar/112

Organizing PHP Batch Jobs

This week at work I got the chance to address the growing number of batch oriented CLI scripts for our main web application.  While they weren't quite unmanageable yet, they were heading in that direction.  There was too much common code, especially with bootstrapping the application and parsing options.  Also,  the location of scripts didn't really make sense... ./bin/bar.php./cron/foo.php, etc.  So I decided to carve out some time and clean it up.

The goals were pretty straight forward:

  • Everything must use the application's model layer.  This is mostly so that the built in caching will be consistent, but also to enforce that all data access goes through the same code.
  • Centralize all CLI option parsing, application bootsrapping, error handling, and multi-tenant logic (this is a multi-tenant SaaS application)
  • Keep the jobs themselves very simple.

With the above in mind, I ended up splitting things up into 3 parts:

Please follow and like us:
Filed under: Code, PHP Continue reading