Skip to content

Instantly share code, notes, and snippets.

@lineker
Created March 9, 2012 00:22
Show Gist options
  • Save lineker/2004309 to your computer and use it in GitHub Desktop.
Save lineker/2004309 to your computer and use it in GitHub Desktop.

Revisions

  1. lineker created this gist Mar 9, 2012.
    19 changes: 19 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    //check if url is available
    function is_available($url, $timeout = 30) {
    $ch = curl_init(); // get cURL handle

    // set cURL options
    $opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
    CURLOPT_URL => $url, // set URL
    CURLOPT_NOBODY => true, // do a HEAD request only
    CURLOPT_TIMEOUT => $timeout); // set timeout
    curl_setopt_array($ch, $opts);

    curl_exec($ch); // do it!

    $retval = curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200; // check if HTTP OK

    curl_close($ch); // close handle

    return $retval;
    }