View Full Version : caching results to .txt files

12-28-2006, 09:11 AM

Im looking to dump some returned values into a txt file so that i can just go to that every 30-60sec instead or having the same thing requested over and over.

The main reason i need this is because the data im pulling can only be given to me every few seconds, so if the page is refreshed within about 5sec then no results are returned and things look rather odd.

Is there a specific way to write the values of $results into cache.txt ??
php.net kindly offered cosh when looking for cache and i cant find anything via google or searching here unfortunately. I wouldnt have thought it was a big task, most of it would just be additional code to check whether to get live info or cached, but until i have it caching info im stuck.

Thanks in advance,

12-28-2006, 09:13 AM
I learned how to write to a text file from here
though storing the results in the text file could get rather large. What about using a database instead?

12-28-2006, 09:24 AM
Thanks, i'll have a rummage through that :D

txt files seem to be 'all the rage' really, in terms of doing this specific job, i suppose your right it could be db'd instead, hadnt thought of that!

The text file would only be about 30k so its not something that would consume the site, is there likely to be any speed difference between pulling it from the .txt file and from the database, the site already does a fair bit of looking in there but if it would be quicker by .txt then thats the route i'd try for first.

12-28-2006, 09:41 AM
If you didn't mind anyone else viewing the text file then you could use it but if security was an issue I wouldn't recommend it.

12-28-2006, 11:10 AM
nah, security isnt an issue here, its basically going through the official routes to get in-game information from the source. To avoid abuse they have a 4-5sec block between connections, and because the site this will go on tells you if the team members are online or not it previously went and asked the main server whenever the page was refreshed, so when flicking through a site you'd occasionallly get no results which usually means people tell me its not working sometimes.
The cached file holds an array of server names and users in there, and then if there name is found then they're displayed as online.

Anyway, just wanted to post and say I got it working and threaded into the original script. Took a little messing about to understand how to go about doing it, but it now works perfectly, checking at >15sec intervals though i'll probably switch that to >30sec once im done playing with a few other bits n peices.

Thanks for pointing me in the right direction,