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 6214303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:51:10+00:00 2026-05-24T06:51:10+00:00

I am obtaining an XML file from a remote server which contains fairly static

  • 0

I am obtaining an XML file from a remote server which contains fairly static data. Here is my code:

$dom = simplexml_load_file("foo.xml");

foreach ($dom->bar->baz as $item) {
echo $item;
}

Since the data is rarely changing, there is no need to ping the server on each page load…How can I cache foo.xml in a simple manner? Keep in mind that I am a beginner…

Thank you!

  • 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-24T06:51:11+00:00Added an answer on May 24, 2026 at 6:51 am

    A very simplistic cache would be to store the xml file into a directory, and updated every hour or so

    $cacheName = 'somefile.xml.cache';
    // generate the cache version if it doesn't exist or it's too old!
    $ageInSeconds = 3600; // one hour
    if(!file_exists($cacheName) || filemtime($cacheName) > time() + $ageInSeconds) {
      $contents = file_get_contents('http://www.something.com/foo.xml');
      file_put_contents($cacheName, $contents);
    }
    
    $dom = simplexml_load_file($cacheName);
    // ...
    

    note: This of course assumes several things like the file was successfully generated, the remote file successfully downloaded, etc.

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

Sidebar

Related Questions

I am obtaining data from a database that is returned in an XML string.
I have media_main.php that is obtaining data from a MySQL database. One of the
Possible Duplicate: Obtaining const_iterator from iterator I want to write a metafunction which returns
I'm working on obtaining bitmap data like ARGB from an image. a). I create
I'm using a JMS queue to read from and insert data into a postgres
So, I'm using the XSLT plugin for JQuery, and here's my code: function AddPlotcardEventHandlers(){
I am familiar with obtaining the contents of a properties file given the name
After obtaining info from an email body, I have a lot of symbols such
I'm obtaining a Vector from a product's API. Vector<?> dataVector = dataAPI.getReturnVector(); The vector
How might one go about obtaining a reference to the DOM script tag that

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.