0

I'm using a cron command to execute a php script that deals with data from an rss feed.

I acquire the data with:

$response_xml_data = file_get_contents("https://itunes.apple.com/us/rss/toppaidmacapps/limit=200/genre=12014/xml");

Then I parse the data, using:

$data = simplexml_load_string($response_xml_data);

function object2array($object)
{
    return json_decode(json_encode($object), TRUE); 
}

$xmlArray = (object2array($data));

Then I iterate through $xmlArray to log and notify me of the data appropriately.

I'm pleased with the way all of this works, except I've picked up on something that makes me wonder if there is something caching the xml data automatically. I ask that, because I was moving the management of all this from one hosted server to another, and happened to have the script running in both places pretty simultaneously. One of them continued to provide back the same data over an hour, while one that was running "fresh" provided new, updated data from the rss feed.

Is there anything that would make me expect that the results of file_get_contents() are being cached? If so, how can I force the script to get fresh results each time?

1 Answer 1

0

If it's being cached, it's not on the file_get_contents end. Apple and other sites use large, worldwide caching networks like Akamai and they're typically eventually consistent - hitting one cache server may return hours-old data while another may be up-to-date. You'll see particularly disparate data if your servers are in different geographic locations.

Nothing you can do about this, generally.

1
  • Ah, that makes sense...I didn't think to question my assumption that both scripts were pulling from the same servers. Nov 20, 2014 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.