note 99109 deleted from function.is-file by danbrown

From: Date: Fri, 30 Jul 2010 16:38:37 +0000
Subject: note 99109 deleted from function.is-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171253@lists.php.net to get a copy of this message
Note Submitter: dv {a-t} rb.no ---- Simple, stable and solid function to check URL's. Will return HTTP status code even on internal errors. K.I.S.S. --- <?php var_dump(URL_GetStatus("http://www.rb.no/")); // URL_GetStatus by Dmitry K Valberg // dv@rb.no // Checks URL and returns easy to use HTTP status codes. // // Will return on error: // 501 - URL syntax error, URL not valid. // 503 - Timeout, connection error etc. // // If url is valid and curl connected to server, //real HTTP code will be returned. function URL_GetStatus($url) { $_r = 501; if (filter_var($url, FILTER_VALIDATE_URL) != false) { try { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $url); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FAILONERROR, 1); @curl_setopt($ch, CURLOPT_NOBODY, 1); @curl_setopt($ch, CURLOPT_TIMEOUT, 5); @curl_exec($ch); $info = @curl_getinfo($ch); curl_close ($ch); if (($info['http_code'] > 100)) $_r = $info['http_code']; } catch (Exception $e) { $_r = 503; } } return $_r; } ?>

« previous php.notes (#171253) next »