forked from fabpot-graveyard/framework-benchs
/
siege.php
executable file
·122 lines (108 loc) · 3.31 KB
/
siege.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env php
<?php
ini_set('error_reporting', E_ALL|E_STRICT);
ini_set('display_errors', true);
// reads a csv file of targets
function fetch_target_list($file)
{
$line = 0;
$handle = fopen($file, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// skip blank lines
$k = count($data);
if (! $k) {
continue;
}
// retain the line of data
for ($i = 0; $i < $k; $i++) {
$list[$line][$i] = $data[$i];
}
$line ++;
}
fclose($handle);
return $list;
}
// write out the siegerc file, mostly so we can maintain a log location
function write_siege_file($vars = array())
{
// the base config vars
$base = array (
'verbose' => 'false',
// csv => true,
// fullurl => true,
// display-id => '',
'show-logfile' => 'false',
'logging' => 'true',
// 'logfile' => '',
'protocol' => 'HTTP/1.0',
'chunked' => 'true',
'connection' => 'close',
'concurrent' => '10',
'time' => '60s',
// reps => '',
// file => '',
// url => '',
// 'delay' => '1',
// timeout => '',
// expire-session => '',
// failures => '',
// 'internet' => 'false',
'benchmark' => 'true',
// user-agent => '',
// 'accept-encoding' => 'gzip',
'spinner' => 'false',
// login => '',
// username => '',
// password => '',
// ssl-cert => '',
// ssl-key => '',
// ssl-timeout => '',
// ssl-ciphers => '',
// login-url => '',
// proxy-host => '',
// proxy-port => '',
// proxy-login => '',
// follow-location => '',
// zero-data-ok => '',
);
// make sure we have base vars for everything
$vars = array_merge($base, $vars);
// build the text for the file
$text = '';
foreach ($vars as $key => $val) {
$text .= "$key = $val\n";
}
// write the siegerc file
file_put_contents("/root/.siegerc", $text);
}
// store logs broken down by time
$time = date("Y-m-d\TH:i:s");
passthru("mkdir -p /var/www/log/$time");
// run each benchmark target
$list = fetch_target_list($_SERVER['argv'][1]);
foreach ($list as $key => $val) {
$name = $val[0];
$path = $val[1];
// write the siegerc file
write_siege_file(array(
'logfile' => "/var/www/log/$time/$name.log",
));
// restart the server for a fresh environment
passthru("/etc/init.d/apache2 restart");
// what href are we targeting?
$href = "http://localhost/$name/$path";
// prime the cache
echo "$name: prime the cache\n";
passthru("curl $href");
echo "\n";
// bench runs
for ($i = 1; $i <= 5; $i++) {
echo "$name: pass $i\n";
passthru("siege $href");
echo "\n";
}
}
// do reporting
echo "Logs saved at /var/www/log/$time.\n\n";
passthru("php /var/www/report.php /var/www/log/$time");
exit(0);