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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:07:15+00:00 2026-05-27T00:07:15+00:00

I am using cURL to get an XML feed and save it into an

  • 0

I am using cURL to get an XML feed and save it into an XML file, like so

if (file_exists($filename) && (filemtime($filename) > time() - 30)) {
    // load cached XML from file
    $output = simplexml_load_file($filename);

    return $output;
} else {
    // Initiate the curl session
    $ch = curl_init();

    // Set the URL
    curl_setopt($ch, CURLOPT_URL, $url);

    // Removes the headers from the output
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // Callback to get custom headers
    curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));

    // Return the output instead of displaying it directly
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // Execute the curl session
    $output = curl_exec($ch);

    // Return headers
    $headers = curl_getinfo($ch);

    // Merge headers into one array
    $this->response_meta_info = array_merge($headers, $this->response_meta_info);

    // Close the curl session
    curl_close($ch);

    // Cache feed
    file_put_contents($filename, $output);

    // XML to object
    $output = simplexml_load_string($output);

    // Return the output as an array
    return  $output;
}

It returns the following http headers

Array(
    [url] => http://example.com
    [content_type] => text/xml
    [http_code] => 200
    [header_size] => 425
    [request_size] => 108
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.677605
    [namelookup_time] => 0.181104
    [connect_time] => 0.342955
    [pretransfer_time] => 0.343036
    [size_upload] => 0
    [size_download] => 6579
    [speed_download] => 9709
    [speed_upload] => 0
    [download_content_length] => 6579
    [upload_content_length] => 0
    [starttransfer_time] => 0.515733
    [redirect_time] => 0
    [expires] => Wed, 23 Nov 2011 15:49:24 GMT
)

I want to use the [expires] => Wed, 23 Nov 2011 15:49:24 GMT header instead of using the time now minus 30 seconds bit of this if statement (file_exists($filename) && (filemtime($filename) > time() - 30)) { as then it will only update the cache when it needs to.

But I can’t work out how to do this.

  • 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-27T00:07:16+00:00Added an answer on May 27, 2026 at 12:07 am

    You can touch() the xml file with the timestamp return by strtotime,
    example :-

    date_default_timezone_set('Asia/Singapore'); // replace to your timezone
    $time = strtotime('Wed, 23 Nov 2011 15:49:24 GMT');
    // after file_put_contents
    // call this to change the time
    touch($filename, $time);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using cURL to get the XML file for my Twitter friend's timeline. (API
I'm using curl and utf8_encode to get the xml from from an rss feed
I'm using PHP and CURL to get XML, but I'm having problems accessing a
I have tried using fopen, file-get-contents and a curl request but I always get
I'm trying to get an xml stream by using curl. I've recieved the string
I am using curl to get a json file which can be located here:
I have a python script that is using curl to post a file into
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
I'm using CURL to connect to multiple xml feeds and process them when the
I am using curl like this: curl -s -F uploaded_file=@/path_to_file;type=text/html -F output=soap12 http://localhost/w3c-markup-validator/check >text.xml

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.