Reading file from another website

Discussion in 'PHP' started by terryuk, Jun 2, 2007.

  1. #1
    I'm trying to put a little script together so a set of my websites can read a txt file from the 'main' website and then echo the HTML from that file. It would be straight forward, but some of the websites won't be on the same server, so i'm confused!?

    Anyone got some suggestions on how I can do this?

    Terry
     
    terryuk, Jun 2, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Usually you would want a good reason to do this. If you must, you can use file handling functions, e.g. file_get_contents() to get data from a remotely hosted file as long as your host supports it (some don't for security reasons). Of course, there is a performance hit so I would suggest keeping a copy of this file on each server. If it is a regularly updated file that you don't want to update on each server manually, maybe setup a cron to update the version on the other servers when the one on the main server changes.
     
    krt, Jun 2, 2007 IP
  3. greenrob

    greenrob Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or you can use file() which will return all the data in array (1 line of data in 1 array)
     
    greenrob, Jun 2, 2007 IP
  4. bochgoch

    bochgoch Peon

    Messages:
    1,918
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'd personally do this by a scheduled cron job that will distribute the main file via mget calls -- this requires UNIX hosting.

    It's a bit convoluted to get into here ... PM me you want further help.
     
    bochgoch, Jun 2, 2007 IP