SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Controlling execution time

    Hey guys I have a script that attempts to open a file at a remote location using get_headers(), If i put in an address that it can't connect to, the script continues to the 60s execution limit of my server and dies.

    I would like the script to stop trying to connect before it reaches that limit and execute my scripts error handler function.

    How could this be achieved. The function to test for the url is:
    PHP Code:
    function url_exists($url){
        
    $AgetHeaders = @get_headers($url);
        if (
    preg_match("|200|"$AgetHeaders[0])) {
            return 
    true;
        }
        else {
            return 
    false;
        }

    It never reaches the else { return false; } statement when it can't connect to the remote server at all

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see fsockopen() set connection timeout.
    see stream_set_timeout() to use while reading it.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you thats exactly what I was looking for, I don't know why I didn't remember the socket functions had timeout settings


Tags for this Thread

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
  •