Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Before we start: I'm a noob.

I'm trying to access YQL to get some information. Grabbing it using PHP's file_get_contents is simple enough, but it seems like either the client's ISP or the server is caching the response. To illustrate the problem, try loading:

--

Refresh that page a couple of times - notice that the 'created' string doesn't change - it should be a couple of seconds off each time you refresh, like this test sample:

--

Now my question is, is this some sort of trick by the sysadmin to cache things, or something that the ISP do? Can I get around it? I must access the YQL via URL because I need to be able to parse it.

(The sysadmin is difficult to reach)

Thanks in advance.


EDIT

I've found out how to get around the cache. You can either randomize string and use the trick mentioned by @Coops below, or use the code here. Most of the times, you can skip the cache by sending Pragma: no-cache header, create a context and use it:

// Create a stream
$opts = array(
    'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Pragma: no-cache"
    )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://example.com');

I still can't figure out whether the cache is configured by sysadmin or the ISP though.

share|improve this question
1  
a general tip, you can add "?blah" on the end of the URL to make it a dynamic request and avoid some browser caches. Also I've used a javascript function in the past to append a random number on the end of the request to some google APIs, as they cache a lot. –  Coops Mar 3 '11 at 10:22
    
@Coops - that's a neat trick! Thanks! I've figured out how to do it the other way though, I'll edit the question in case someone happens to have the same problem. –  rickchristie Mar 3 '11 at 10:26
add comment

1 Answer

You can check some specific headers from responses: Age, Expires, ETag, Via. Values of this headers can help you to determine whatever you need. For details and header descriptions see section Responses in List of HTTP headers.

For example, value of Via header can tell you that response was received from Proxy which can have requested by you data in his own cache.

share|improve this answer
    
agree - have a good look at the headers or maybe post them up here. wget --spider -S http://www.foo.com/ –  James C Apr 21 '11 at 12:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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