Boost PHP Speed With “If-Modified-Since” [2/4]

October 5, 2006 § 33 Comments

[magnifying glass]

Improve PHP Performance

This post continues the series where we embarked on the seemingly simple task of enabling If-Modified-Since headers for PHP scripts. What I discovered is that it’s not as easy at it seems!

Series Index

Part II: Watching IMS In Action

Up to now I’ve called this process “IMS”. What we’re really doing is a conditional GET. In the next section we’ll go over several useful tools for dissecting a conditional GET and watch real data to help explain the challenges and possible solutions involved.

Required Tools

To perform and watch a conditional GET, you need the following (the tools I use in parenthesis).

  • An HTTP Monitoring Tool (Fiddler 1.2.0.7)
    Fiddler is an HTTP debugging proxy written by Eric Lawrence of Microsoft that allows you to examine request and response header values as they happen. This the tool I used to check which sites use gzip in a previous tutorial. You can also craft custom requests, attach scripts to particular behaviors and filter various response types. I mostly use it as a quick and dirty way to see what’s getting loaded and which requests cause errors.
    http://www.fiddlertool.com/fiddler/

     

  • An HTTP 1.1-Compliant Browser (FireFox 1.5.0.7)
    FireFox is of course, the tool for compatible browsing, but any modern browser should work – the IMS caching standard has been around for years.
    http://www.mozilla.com/firefox/

     

  • Any scripting/CGI language that allows raw HTML generation (PHP 5.0)
    PHP is perhaps overkill for demonstration purposes (you could use a simple batch file), but it is very common so I suspect this should work for most readers. PHP is the scripting language upon which WordPress is based.
    http://www.php.net/downloads.php

Let’s take a peek at the data exchanged between a browser and server…

Example 1: Watch HTML Caching With Fiddler

First, let’s look at what a normal HTML file looks like with Fiddler. The HTML is stripped to the bare minimum for simplicity:

[first pass]
(screenshot: First pass of static.html)

Because static.html hasn’t been loaded before, the browser does NOT send an IMS date, but the server returns a Last-Modified and ETag for next time.

[second pass]
(screenshot: Second pass of static.html)

Press F5 to reload and this time the server responds with a 304 Not Modified, as expected.

All of this has been automatic so far. Now let’s look a more interesting page…

Example 2: Watch a Simple PHP Page

We’ll execute a basic PHP command (normally this would be a data query or series of pre-processor commands for the server, of course).

Press F5 and notice that even though the file has not changed, the server still generates the content each time. No big deal for a small file, but in a WordPress environment, you’re looking at upwards of 100k of related data requested from a database for each user, rss aggregator and indexing robot that visits the site!

Speaking of unnecessary data, I’ll forego the fat screenshot images – you get the idea.

Example 3: Watch a PHP File Using Conditional GET

This is where it gets fun – a conditional GET.

For simplicity, the next example does not actually store or retrieve a LM date for the file – we’re going to hard code one in the header and embed the doConditionalGet function in the same file. The base code comes courtesy of Simon Willison.

As predicted, the file only gets loaded the first time and as long as the cached copy still exists, should NEVER load again for the same browser.

Next Steps

So, are we done?

No, because now we have to figure out how we’re going to track the LM date for this content without creating more of the server load we set out to prevent! We’ll cover this in Part IV: Implementing IMS On WordPress.

But first, we’ll spend time in Part III understanding how all of this specifically impacts content aggregators and RSS feeds.

Homework Exercise

To conclude this section, I want to introduce one other very useful tool for webmasters: the Cacheability Test by Mark Nottingham.

This tool analyzes a URL for the presence of cache-ready values like Last-Modified and Entity Tag, as well as a few I haven’t mentioned yet

  • Cache Control
  • Expires
  • Cookies
  • Content Length

Your homework is to perform tests on the following URLs.

To speed up cacheability tests, be sure to uncheck “include referenced frames, images and objects”.

Question: Why will http://www.vibetechnology.com/vt/index.php NEVER be cacheable?

« Previous Part I: Understanding IMS
Next » Part III: Using IMS For Optimized RSS Feeds

Advertisements

§ 33 Responses to Boost PHP Speed With “If-Modified-Since” [2/4]

  • perfectforex says:

    Good do be on board I am following this board since a long time For more information have a look at traders site.

  • Reinaldo says:

    A weight loss program that is certainly high by utilizing fiber provides numerous advantages including
    cleansing and detoxification in the system,
    repair off blood glucose levels and high levels of at healthy levels, online marketing of weight-loss more effective
    weight reduction. When you are building villages in the Clash of
    Clans, we would strongly recommend you to use the basics of urban planning
    in order to build a tightly spaced property.
    In addition, the top players in the top three clans receive gems from the weekly tournament.

  • So you please tolerate a few grammar and syntax problems as you
    read this. You win or lose trophies based on if you win or lose
    attacks or defenses. You start in a set of a beautiful island where your peaceful village is surrounded by beaches
    and woods until the enemies known as the Black – Guard
    led by Lieutenant Hammerman invades your island.

  • Abby says:

    A weight loss program that is certainly high by utilizing fiber provides numerous advantages including cleansing and detoxification in the system,
    repair off blood glucose levels and high levels of at healthy levels, online marketing of weight-loss more effective weight reduction. Super – Cell made the Clash of Clans that one could
    avail through downloading the experience free of charge in the actual Apple application store.
    The enemy has outlined his strategy for defeating the West and its allies.

  • A weight loss program that is certainly high by utilizing fiber provides numerous advantages including cleansing and detoxification in the system, repair off blood glucose levels and high levels of at healthy levels, online marketing
    of weight-loss more effective weight reduction. Games that have a label
    of M (for mature) are not for everyone; you should have rules in your house related to who can play what games.

    The majority of games include audio sections in their menus.

  • Apart from strengthening your defence, the unique abilities of these weapons can come
    in very handy when trying to withhold an enemy attack.
    Talking to one of these guys was like talking to a hundred.
    The majority of games include audio sections in their menus.

  • www.jckh.org says:

    Boom Beach joins the ranks of being Supercell’s latest game released after their success with Clash of Clans and Hay Day.
    Take the time to think carefully before choosing which gaming system you will buy.
    Non-profit organizations, governmental agencies,
    and educational institutions all use time clock software to track time spent on different projects and activities.

  • Don’t make impulse purchases, particularly of new blockbuster games.
    If your children want to access a site where their friends are playing, look
    at the site first. You start in a set of a beautiful island
    where your peaceful village is surrounded by beaches and woods until the enemies known as the
    Black – Guard led by Lieutenant Hammerman invades your
    island.

  • So you please tolerate a few grammar and syntax problems as
    you read this. Take the time to think carefully before choosing which gaming system you will
    buy. Ask yourself what kind of games you want to play and which features you need.

  • Kendrick says:

    A weight loss program that is certainly high by utilizing fiber provides numerous
    advantages including cleansing and detoxification in the system,
    repair off blood glucose levels and high levels of at healthy levels, online marketing of
    weight-loss more effective weight reduction. Take the time to think carefully
    before choosing which gaming system you will buy. Ask yourself what kind of games you want to play and which features you need.

  • A weight loss program that is certainly high by utilizing fiber provides numerous advantages including cleansing and detoxification in the system, repair
    off blood glucose levels and high levels of at
    healthy levels, online marketing of weight-loss more effective weight reduction. Talking to one of these guys was like talking to a hundred.
    You start in a set of a beautiful island where your peaceful village is surrounded by beaches and
    woods until the enemies known as the Black – Guard
    led by Lieutenant Hammerman invades your island.

  • Buford says:

    You shouldn’t buy a game if you are not sure whether you
    are going to like it. Super – Cell made the Clash of Clans that one could avail through downloading the experience free of charge in the actual Apple application store.
    Ask yourself what kind of games you want to play and which features you need.

  • You shouldn’t buy a game if you are not sure
    whether you are going to like it. Super – Cell made the Clash of Clans
    that one could avail through downloading the experience free of charge in the actual Apple
    application store. Romeo’s biggest flaw can be
    identified in two: (1) his over emotional attitude
    which pushes him to (2) act recklessly which brought him the conflicts and struggles of his character in the story.

  • Ada says:

    Boom Beach joins the ranks of being Supercell’s latest game released after their
    success with Clash of Clans and Hay Day. If your children want to access a site where their
    friends are playing, look at the site first.

    Ask yourself what kind of games you want to play and which features you need.

  • Mariam says:

    Consoles let you control their privacy, security settings, and content since they can bypass these restrictions
    online. com, the Ultimate Mobile Currency Marketplace, your one stop for all your mobile currency needs.
    The enemy has outlined his strategy for defeating the West and its allies.

  • So you please tolerate a few grammar and syntax problems as you read this.
    If your children want to access a site where their friends are playing, look at the site first.
    The majority of games include audio sections in their menus.

  • Aidan says:

    When you sit for many hours on end, you can injure your back or even become obese.
    Talking to one of these guys was like talking to a hundred.
    In addition, the top players in the top three clans receive gems from the weekly tournament.

  • Letha says:

    After all, gaming is supposed to be fun and refreshing,
    not a health hazard. When you are building villages in the Clash of Clans, we would strongly recommend you to use the basics
    of urban planning in order to build a tightly spaced property.

    The majority of games include audio sections in their menus.

  • Emilia says:

    You shouldn’t buy a game if you are not sure whether you are going to like it.
    You win or lose trophies based on if you win or lose attacks
    or defenses. Non-profit organizations, governmental agencies, and
    educational institutions all use time clock software
    to track time spent on different projects and activities.

  • Millie says:

    A weight loss program that is certainly high by utilizing
    fiber provides numerous advantages including cleansing and detoxification in the system,
    repair off blood glucose levels and high levels of at healthy levels, online marketing of weight-loss more effective weight reduction. Talking to one of
    these guys was like talking to a hundred. The majority of games include audio
    sections in their menus.

  • Enriqueta says:

    So you please tolerate a few grammar and syntax problems
    as you read this. When you are building villages
    in the Clash of Clans, we would strongly recommend you to use the basics of urban planning in order to build
    a tightly spaced property. In addition, the top players in the top three clans receive gems from the weekly tournament.

  • Don’t make impulse purchases, particularly of new blockbuster games.
    Take the time to think carefully before choosing which gaming system you will buy.
    Romeo’s biggest flaw can be identified in two:
    (1) his over emotional attitude which pushes him to (2) act recklessly which
    brought him the conflicts and struggles of his character in the story.

  • You can also break open the capsules of Vitamin E and apply the liquid directly onto the
    cold sore. 05) less HSV infections, symptoms were significantly (p less than 0.
    Between cold sores, as a preventative, 500 to
    1000 mg.

  • Christen says:

    Mostpeople don’t realize that lack of oxygen is not only the cause of
    herpessimplex but is also the cause of all most diseases.
    However, you need to take the first step by searching for different ways to help you release stress naturally.
    The reality is that both are names for the Herpes Simplex Type 1 Virus.

  • Molly says:

    Her offering is thoroughly explained, and provides security for anyone who may wish to try her methods.
    For intermittent cold sores, you can purchase many different kinds
    of cold sore treatments over-the-counter. Bacterial
    Vaginosis (BV) on the other hand is as a result of
    bad bacterial such as haemophilus vaginitis growing at rate that the body’s immune system can’t keep in check.

  • Bridget says:

    Her offering is thoroughly explained, and provides security for anyone
    who may wish to try her methods. Plant medicine contains certified organic medicinal plant extracts and antiviral essential oils.
    Most women do not feel comfortable talking about
    problems down below even with their doctors.

  • Ramiro says:

    If they are still asking their doctor, is there a proven cure for genital
    herpes and not having any success with their treatment, then they
    probably aren’t using it. Are people who have been infected with HIV may be
    married and have children. Nowadays, several people suffer from
    food poisoning which is caused due to the attack of Giardia,
    an amoeba that hampers functioning of digestive system.

  • Verena says:

    There are lots of natural remedies that have been found to be very effective and some of these are even prescribed by doctors as a way of treating this condition. Patients with symptomatic or asymptomatic recurrences can transmit infection to sexual
    partners. They also reduce pain, itching and fever and lower chances of transmission to other people.

  • Jocelyn says:

    If they are still asking their doctor, is there a proven cure for genital herpes and not having any success with their treatment, then they probably aren’t using it.
    By having a weak immune system, you are at risk of having an outbreak.
    Between cold sores, as a preventative, 500 to 1000 mg.

  • Shawnee says:

    There are lots of natural remedies that have been found to be very effective
    and some of these are even prescribed by doctors as a way of
    treating this condition. 05) less HSV infections, symptoms
    were significantly (p less than 0. Bacterial Vaginosis (BV) on the other hand is as
    a result of bad bacterial such as haemophilus vaginitis growing at rate that the body’s immune system can’t keep
    in check.

  • Jill says:

    One-third of patients are estimated to have recurrences in excess of eight or nine
    per year, one-third will have two to three recurrences per year, and the remaining one-third will have between four and seven recurrences per
    year. Are people who have been infected with HIV may be married and have
    children. The reality is that both are names for the Herpes
    Simplex Type 1 Virus.

  • If they are still asking their doctor, is there a proven cure for genital herpes and not having any success with their treatment, then they probably aren’t
    using it. Are people who have been infected with HIV may
    be married and have children. The statistics are much higher than we would expect
    them to be, but this should be a relief, rather than something to worry about.

  • I read this piece of writing fully on the topic of the resemblance of most recent and previous
    technologies, it’s remarkable article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Boost PHP Speed With “If-Modified-Since” [2/4] at VibeTalk by Vibe Technology.

meta

%d bloggers like this: