1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Caching problem loading a url with file_get_contents

Discussion in 'PHP' started by spacific, Apr 7, 2007.

  1. #1
    Hi,

    I am loading another web page (from a different server) using file_get_contents with a url for filename. Works well, but it isn't updating as that web page changes. I assume that the loaded page is being cached somewhere. How can I clear that cache, given that I have no control of the web page I am trying to load (and have no idea at which point the caching is being done!) ?
    SEMrush
    Thanks.
     
    spacific, Apr 7, 2007 IP
    SEMrush
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    PHP does cache some data for file access but it doesn't cache the contents of a file.

    You can try clearstatcache() but it really shouldn't work.

    That just leaves caching on the other server but if you browse to the site manually and get different content this also seems unlikely. Are you passing variables to the site in either GET or via a cookie? These may cause different versions of a page to be served to a browser.
     
    streety, Apr 7, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,150
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You can try opening the file by sending a dummy random non-existent variable, like this:

    
    $url = 'http://example.com/file.html?r=' . rand(0, 9999);
    
    PHP:
    But as Streety said, I don't think PHP caches the contents of a file.
     
    nico_swd, Apr 7, 2007 IP
  4. spacific

    spacific Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    streety: Yes I already tried clearstatcache() in a vain hope: no good as expected!

    nico_swd (and streety): BRILLIANT! It worked. What a nice idea. Many many thanks.

    Pascua Feliz!
     
    spacific, Apr 7, 2007 IP