SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    romania
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to catch timeout errors and continue?

    Hi!

    My PHP script connects to a server to get a html page. Something like this:

    $url ="http:://www.aaa.com/....";
    set_time_limit(30); //30 seconds for each page
    $html = file_get_contents($url);

    The problem is: I want to set a reasonable time limit, and , if the server does not respond during this time, I want to CONTINUE execution of the script.

    I tried to write my own error handler and called set_error_handler. The problem is that FATAL errors (timeout is a fatal error) cannot be caught with custom error handler (not in PHP 4.3.x at least).
    So the script just dies, wich is uunacceptable. I just want to display a message that timeout has occured and continue execution.

    Any idea how to do that?
    I don't have access to the php.ini (since the script will be hosted).

    Thanks in advance

  2. #2
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could try to use cURL
    if your host has it installed/enabled

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Indianapolis
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than using file_get_contents, you may want to look into using fopen() or fsockopen() with stream_set_timeout().
    Dave Scott
    President/CEO
    The Sonic Group, LLC


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
  •