• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

php caching problem

MrScott81

Golden Member
So I have a php page that I use to grab NFL scores for a family football pool that I run.

I previously used to web scrap an ESPN website but they changed their format and I sought an easier approach. I finally ended up finding a nice little xml file provided by nfl.com that is very minimal and contains all of the information I need.

Example url:
http://www.nfl.com/ajax/scorestrip?season=2015&seasonType=REG&week=15

This xml file gets updated in near real time and is perfect, except for one minor problem that I'm running into and that's the fact that I keep getting cached results. The ONLY way that I have been able to get around this is by setting up a cron job to use wget to download the file every X amount of minutes and have my php parse the downloaded file.

Things I have tried that DO NOT work:
1) Adding a dummy variable to the URL I am trying to scrape from to have a "unique" url. Example:
http://www.nfl.com/ajax/scorestrip?season=2015&seasonType=REG&week=15&dummy=1923751975

2) Using php to call exec which runs a wget command (same command that I setup in the cron job). For some reason, this still gets the cached result.

3) All sorts of php header variables to try to prevent caching.

Here's a code snippet of my stuff:
Code:
<?php
header("Content-type: text/xml");
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: Sat, 26 Jul 1997 05:00:00 GMT");

$url = "http://www.nfl.com/ajax/scorestrip?season=".
			$year."&seasonType=REG&week=".$week."&dummy=".time();
$xml = simplexml_load_file($url);

Any suggestions would be appreciated.
 
The headers affect requests between the end client (your browser) and your php server, not between your server and the third party url.

Anyhoo, afaik, PHP doesn't provide any caching for HTTP downloads or data retrieved from streams so any caching issues that you're encountering is either on your ISP end, browser end, or third party server's end unless you've installed a server module that caches key-value pairs.

What's the output of phpinfo(); ?

Also, why do you think the results are "cached" ?

And lastly, if you do a wget <url> twice 5 minutes apart, what SHOULD the difference be between the two result sets?
 
Last edited:
Please disregard this thread, I'm an idiot. It turns out the file was not getting overwritten because of permissions problems. Cron worked because I had it running under root.

Sometimes I feel so stupid 😛
 
Back
Top