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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
function url_exists( $baselink = NULL ) {
if( empty( $baselink ) ){
return false;
}
$ch = curl_init( $baselink );
// Set a timeout
curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 );
// Set NOBODY to true to make a HEAD-type request
curl_setopt( $ch, CURLOPT_NOBODY, true );
// Allow follow redirects
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
// Receive the response as string, not output
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$data = curl_exec( $ch );
// Get the response code
$httpcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
// close connection
curl_close( $ch );
// Accept only answer 200 (Ok), 301 (permanent redirect) or 302 (temporary redirect)
$accepted_response = array( 200, 301, 302 );
if( in_array( $httpcode, $accepted_response ) ) {
return true;
} else {
return false;
}
}
function secToDuration($seconds){
$minutes = intval($seconds/60);
$seconds = ($seconds - ($minutes * 60));
return $minutes . ' minutes ' . $seconds . ' seconds';
}
function bytes($a) {
$unim = array("","K","M","G","T","P");
$c = 0;
while ($a>=1000) {
$c++;
$a = $a/1000;
}
return number_format($a,($c ? 2 : 0),",",".")." ".$unim[$c];
}
|