Calling URLs without waiting

Discussion in 'PHP' started by grunff, Sep 22, 2008.

  1. #1
    Hi all,

    We currently have a system which updates a number of websites by calling URLs on those sites. This is done like this:

    fopen("http://www.myurl.com/", "r");
    Code (markup):
    The problem is that PHP waits until it gets a response from each site before moving on. This can cause delays at busy times.

    Is there any way to carry out the same URL call without waiting for the response?

    TIA
     
    grunff, Sep 22, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Either:

    Using system/exec to fork a background copy of your PHP script

    Or:

    Use www.php.net/fsockopen and simply close the socket before reading any output (better option).

    Jay
     
    jayshah, Sep 22, 2008 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    you can fork the process and come back to it later, i believe. check _http://uk3.php.net/manual/en/ref.pcntl.php although I have not done this. depends on your needs - if you rely on data being parsed from the html of the remote page to complete the building of your page, then you just have to wait. best practice is - for a busy site to a site with / via a poor network connection - crontab a script to go and fetch contents every 5 or 10 minutes and write it to a local DB, then just get your script to read from that DB. Of course, it will only work if you don't deal with any critical data that needs to be updated to the minute or second...

    another thing i tend to do for similar problems is ajax it (which is in effect going to fork it) then apply the results to the page dom as needed.
     
    dimitar christoff, Sep 22, 2008 IP