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.

Stop file_get_contents.

Discussion in 'PHP' started by bquast, Feb 21, 2008.

  1. #1
    Well I have been working on a backlinks checker, its pretty simple, checks the page to see if my url is included in their page.

    
    $htmlString=file_get_contents($line[0]);
    
    if (eregi('href=\"http://www.proxyslisted.com\" ', $htmlString)) {
       echo '<div class="backlinks"><a href="goto.php?id='.$counter.'" title="'.$line[0].'">'.$line[0].'</a></div>';
    }
    PHP:
    So basically what I am curious about is how do I stop it from echoing out an error I have tried damn near everything and still I have got no where, checked the manual inside and out.

    I have just shut off error_checking so that it doesn't display anything but even still I want the script to run right not wrong.

    thanks,
    Brett
     
    bquast, Feb 21, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Feb 21, 2008 IP
    bquast likes this.
  3. bquast

    bquast Active Member

    Messages:
    275
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    78
    #3
    yes sorry that is what I meant to say, and also is their anyways to speed this up, shouldn't i be able to close the file_get_contents everytime etc.?

    and yeah that worked perfectly never new about the @ sign like that thanks nico

    thanks,
    Brett
     
    bquast, Feb 21, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Not really. The speed depends on the other server. Your server makes an HTTP request to it, and it just takes its time.

    There's no need to close it. file_get_contents() will close the connection at the end of each request.
     
    nico_swd, Feb 21, 2008 IP
  5. walkere

    walkere Active Member

    Messages:
    112
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    file_get_contents is pretty much a shortcut for fopen, fread, and fclose. So no, you don't need to close the file each time - file_get_contents already does that.

    As for the speed issue, yes and no.

    There's probably not much you can do to speed up the execution of the php script. Sending an http request (like opening a URL with file_get_contents) will take time because you have to wait for the other server to respond - sometimes several seconds.

    What you can do is use AJAX to make the request. This won't speed up the request, per se, but it will allow the page to load while you wait for the links to get checked - and this would be very advantageous if you were checking multiple pages at once.

    To do that, you first load the page. Once the page loads, it executes some Javascript that creates an AjaxRequest. The AjaxRequest calls the php script and gets the results from the remote page. You then insert the results of your AjaxRequest onto your page and update it in real time.

    - Walkere
     
    walkere, Feb 21, 2008 IP
  6. fallen

    fallen Well-Known Member

    Messages:
    162
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    118
    #6
    you can always read line by line and stop when the desired result has been found. Just use:
    http://www.php.net/fgets
     
    fallen, Feb 21, 2008 IP
  7. dansgalaxy

    dansgalaxy Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I understand the idea of AjaxRequests but have yet to figure out how to use them, how could this be done for this script? can your provide a example?
     
    dansgalaxy, Feb 22, 2008 IP
  8. walkere

    walkere Active Member

    Messages:
    112
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #8
    If you want to get a grasp on how to use AJAX, I'd suggest reading the first couple articles in the IBM Developer Works series. It gives you a great overview of how AJAX works and some code examples to get started.

    Once you've done that, find an AJAX framework, like prototype.js. There's some documentation on how to use prototype.js on their site. If you understand the concept, then prototype is very easy to implement.

    Good luck,
    - Walkere
     
    walkere, Feb 23, 2008 IP
  9. lanclip

    lanclip Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i test my api site by load json file. I use file_get_contents but it seem to be slow. Anybody should me idea for this?
    Thanks
     
    lanclip, Feb 24, 2011 IP