file_get_contents() hangs on some sites?

Discussion in 'PHP' started by skyl4rk, Feb 14, 2008.

  1. #1
    I am trying to search url pages for a search term and grab some text around the search term. The seed url's are in a large database. For some reason it hangs on a few sites.

    Here is one site it usually hangs on:

    http://www.ravencruise.com/logbooks.htm

    Is there a way to time out file_get_contents()?
     
    skyl4rk, Feb 14, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try adding the following somewhere above your file_get_contents call:

    ini_set('default_socket_timeout',    #);
    PHP:
    Replace # with a new number to set it to. I am not really sure what numbers it uses by defaults and such however you can call this function first to check what it currently is:

    $current_timeout = ini_get('default_socket_timeout');
    PHP:
    By setting the value lower, it will only affect it for the current script run, and it will cause it to timeout sooner. Hopefully it works for you. You can also, if your host allows it, create a php.ini file in the same directory as the script and place the following in it:

    default_socket_timeout = #

    Again, replacing # with a new value.
     
    zerxer, Feb 15, 2008 IP