Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:16:41+00:00 2026-05-27T01:16:41+00:00

How can I use HTTP headers to control when my cache should be updated?

  • 0

How can I use HTTP headers to control when my cache should be updated?

At the moment I am using cURL to grab a live XML feed and then save it into an xml file.
The feed also sends HTTP headers notifying you of when it will be updated. The update can be anywhere between 30seconds and 3mins.

The header looks like this

Expires: Mon, 22 Nov 2011 10:01:22 GMT

and this is what I am currently using to check every 30seconds

if (file_exists($filename) && (filemtime($filename) > time() - 30)) {

I would prefer it to only update based on what the HTTP headers say.

How would I go about doing so?

Also is there a better way of caching this XML feed rather than saving it to a XML file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:16:41+00:00Added an answer on May 27, 2026 at 1:16 am

    first of all you will have to parse the date given in the headers:

    $header = "Expires: Mon, 22 Nov 2011 10:01:22 GMT";
    preg_match(
        "/Expires: [A-Za-z]+, ([0-9]{1,2}) ([A-Za-z]+) ([0-9]{4}) ([0-9:]+) ([A-Z]{3})/", 
        $header,
        $matches
    );
    $months = array(
        "Jan" => "01",
        "Feb" => "02", 
        "Mar" => "03",
        "Apr" => "04",
        "May" => "05",
        "Jun" => "06",
        "Jul" => "07",
        "Aug" => "08",
        "Sep" => "09",
        "Oct" => "10",
        "Nov" => "11",
        "Dec" => "12"
    );
    $day = $matches[1];
    $month = $months[$matches[2]];
    $year = $matches[3];
    $time = $matches[4];
    $zone = $matches[5];
    
    $date = new DateTime("$year-$month-$day $time", new DateTimeZone($zone));
    

    then you can check this against the actual time and only execute the update if the $date from the last update is reached

    $now = new DateTime();
    if($now > $date);
    

    you should save the $date in a file or DB after you downloaded the XML and parsed the date.
    next time you execute the script just check the saved date against the new DateTime() to see if you already have to update it, if not you can load the saved XML from the file.

    saving the XML as file is good, you might save it to a Database, but I would not set up a DB only for saving one XML-Structure. If you want to keep a history of old XMLs the DB makes sense again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way I can use URLs like: http://www.blog.com/team-spirit/ instead of http://www.blog.com/?p=122 in
We can use solr range query like: http://localhost:8983/solr/select?q=queryStr&fq=x:[10 TO 100] AND y:[20 TO 300]
How can I use the ListView_GetBkImage macro: http://msdn.microsoft.com/en-us/library/bb761246(v=VS.85).aspx ... from a C#/WinForms application? I
Any time I use the recipe at http://code.activestate.com/recipes/134892/ I can't seem to get it
I'm trying to figure out the best HTTP headers to send for four use
The core question is about the use of the HTTP Headers, including Range ,
I'm trying to install the PECL extension pecl_http so that I can use PHP's
You can use more than one css class in an HTML tag in current
You can use a standard dot notation or a method call in Objective-C to
I can use properties of an Excel Worksheet to tell if the worksheet is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.