-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsurl.php
More file actions
104 lines (95 loc) · 2.64 KB
/
surl.php
File metadata and controls
104 lines (95 loc) · 2.64 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/php
<?
/*
* $params = array('url' => '',
* 'host' => '',
* 'header' => '',
* 'method' => '',
* 'referer' => '',
* 'cookie' => '',
* 'post_fields' => '',
* ['login' => '',]
* ['password' => '',]
* 'timeout' => 0
* );
*/
require_once('surl.config.php');
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function report($stats)
{
global $nr_requests;
$slow=0;
echo "Time[s]\t \tPercent(Hits)\n";
foreach ( $stats as $time => $count )
{
$percent = round(100*($count/$nr_requests), 2);
echo "${time}\t<=\t${percent}% (${count} hits)\n";
if( $time > 1 ) $slow+=$count;
}
echo "Slow requests: " . round(100*($slow/$nr_requests), 2) ."%\n";
}
function hit_($url, $vhost=NULL, $login=NULL, $password=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if(!empty($login) and !empty($password) )
curl_setopt($ch, CURLOPT_USERPWD, "${login}:${password}");
if(!empty($vhost))
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ${vhost}"));
curl_setopt($ch, CURLOPT_NOBODY, true);
$start=microtime_float();
if(!curl_exec($ch)) die("Cant exec curl request!");
$end=microtime_float();
$status=curl_getinfo($ch);
if($status['http_code'] != 200 )
die("Http repsponse code ${status['http_code']} returned by $url!");
//print_r(curl_getinfo($ch));
curl_close($ch);
$delta=round($end-$start, 1);
if($delta < 1 )
{
// echo ".";
$delta=round($end-$start, 1);
}
else
{
// echo "-${delta}-";
$delta = round($delta,0);
}
return($delta);
}
$testfile=$files[2];
for($i=0;$i<$nr_requests;$i++)
{
$delta = (string)hit_("http://${origin1}${testfile}", '', $ologin, $opass);
if(empty($o1stats[$delta])) $o1stats[$delta]=0;
$o1stats[$delta]++;
$delta = (string)hit_("http://${origin2}${files[1]}", '', $ologin, $opass);
if(empty($o2stats[$delta])) $o2stats[$delta]=0;
$o2stats[$delta]++;
$delta = (string)hit_("http://${l2}${testfile}?cdn_hash=" . md5("${testfile}${zonepass}") , $zonename);
if(empty($l2stats[$delta])) $l2stats[$delta]=0;
$l2stats[$delta]++;
$delta = (string)hit_("http://${l1}${testfile}?cdn_hash=" . md5("${testfile}${zonepass}") , $zonename);
if(empty($l1stats[$delta])) $l1stats[$delta]=0;
$l1stats[$delta]++;
usleep(200000);
}
/* Print results */
echo "\nOrigin1:\n";
ksort($o1stats);
report($o1stats);
echo "Origin2:\n";
ksort($o2stats);
report($o2stats);
echo "L1:\n";
ksort($l1stats);
report($l1stats);
echo "L2:\n";
ksort($l2stats);
report($l2stats);
?>