-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.php
61 lines (46 loc) · 1.4 KB
/
benchmark.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
<?php
if (PHP_SAPI != 'cli') {
echo 'This script runs only in CLI mode.';
exit();
}
if (count($argv) < 3) {
$script = end(explode(DIRECTORY_SEPARATOR, $argv[0]));
echo "Usage:\r\n";
echo "php {$script} benchmarked_url competitor_url1 [competitor_url2 ...]\r\n";
exit();
}
require_once('src/autoload.php');
try {
$tested = new Website($argv[1]);
$competitors = array();
for ($i = 2; $i < count($argv); ++$i) {
$competitors[] = new Website($argv[$i]);
}
} catch (InvalidArgumentException $e) {
exit('Error: ' . $e->getMessage() . "\r\n");
}
$b = new Benchmark($tested, $competitors);
$info = new BenchmarkInfoTxt($b);
echo 'Testing...' . "\r\n";
$b->performTests();
// report results
$report = $info->getData();
echo $report;
$log = new SplFileObject('log.txt', 'a');
$log->fwrite($report);
$log = null;
// additional conditons
$slower = function(Website $w, Website $c) {
return $w->getLoadTime() > $c->getLoadTime();
};
$twiceAsSlow = function(Website $w, Website $c) {
return $w->getLoadTime() >= 2 * $c->getLoadTime();
};
if ($b->isConditionMet($slower)) {
$mail = new Mailer();
$mail->send('[email protected]', 'Benchmark notification', 'Tested website loaded slower than one of the competitors.');
if($b->isConditionMet($twiceAsSlow)) {
$sms = new SMS(array('user', 'passwd'));
$sms->send(array('+48 123456789'), 'Tested website loaded twice as slow as one of the competitors.');
}
}