SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow avoid fatal error of file_get_contents?

    I have a script that uses file_get_contents. However, sometimes the script times out and I get a fatal error. Can I limit file_get_contents execution time and redirect to another page to avoid the fatal error? Please Help. Basically, if the file isn't retrieved within say 10 seconds, I want to redirect.
    Last edited by stuffedbuggy; Nov 19, 2008 at 11:25.
    You know you cooler than me...

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Is that file on your own server?

    If it is not, then why not use cURL to get some meta data about the file first, info I think it is called, before going to the trouble of getting the file if you have persistent network problems.

  3. #3
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I predetermine how long it's going to take to get the contents?
    I've never had much experience with CURL.
    Connect_Time_Real??
    You know you cooler than me...

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,398
    Mentioned
    65 Post(s)
    Tagged
    1 Thread(s)
    You can attach a stream context to the file_get_contents call, in that context you can define a retrieval timeout.
    Salathe
    Software Developer and PHP Manual Author.

  5. #5
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. Do you have an example?
    You know you cooler than me...

  6. #6
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After searching all day, I found this. This may be what I need but I don't quit understand how to use it. If anyone knows, I'd appreciate it. here's the link:
    http://www.planetmysql.org/entry.php?id=12850
    You know you cooler than me...

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •