forked from jpwright/debcite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.url.php
37 lines (32 loc) · 1.01 KB
/
class.url.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
class Url
{
/**
* Check if an url is existed
*
* @param string $url
* @access static
* @return bool True if the url is accessible and false if the url is unaccessible or does not exist
* @throws Exception An exception will be thrown when Curl session fails to start
*/
public static function exists($url) {
if (null === $url || '' === trim($url))
{
throw new Exception('The url to check must be a not empty string');
}
$handle = curl_init($url);
if (false === $handle)
{
throw new Exception('Fail to start Curl session');
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
// grab Url
$connectable = curl_exec($handle);
// close Curl resource, and free up system resources
curl_close($handle);
return $connectable;
}
}
?>