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!) ?

    Thanks.
     
    spacific, Apr 7, 2007 IP
  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,153
    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:
    1
    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
    JEET likes this.
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    I think it was more of a browser issue than with php
     
    NetStar, Dec 14, 2019 IP
  6. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    NetStar
    You really never understand the question, do you? Bouncing a 12 year old "solved" thread... Where is browser used in file_get_contents function call?
     
    JEET, Dec 14, 2019 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #7
    For whatever reason the thread was on the top when I replied. I think perhaps someone elses response was deleted. And of course I understand the question. He stated the web page content was NOT updating. The content is based off from the fetched page that was passed to the browser. Which means the caching "issue" was due to the browser viewing the content and NOT relating to the PHP function that retrieves the data. Genius.
     
    NetStar, Dec 14, 2019 IP