-
Notifications
You must be signed in to change notification settings - Fork 715
/
gethar.php
75 lines (65 loc) · 2.13 KB
/
gethar.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
<?php
include './settings.inc';
$results = array();
// see if there is an existing test we are working with
if (LoadResults($results)) {
// count the number of tests that don't have status yet
$testCount = 0;
foreach ($results as &$result) {
if (
array_key_exists('id', $result) &&
strlen($result['id']) &&
array_key_exists('result', $result) &&
strlen($result['result'])
) {
$testCount++;
}
}
if ($testCount) {
echo "Retrieving HAR files for $testCount tests...\r\n";
if (!is_dir('./har')) {
mkdir('./har');
}
$count = 0;
foreach ($results as &$result) {
if (
array_key_exists('id', $result) &&
strlen($result['id']) &&
array_key_exists('result', $result) &&
strlen($result['result'])
) {
$count++;
echo "\rRetrieving HAR for test $count of $testCount... ";
$file = $result['id'] . '-' . BuildFileName($result['url']);
if (strlen($file) && !is_file("./har/$file.har")) {
$response = file_get_contents("{$server}export.php?test={$result['id']}&medianRun=fastest&run=median&bodies=1&pretty=1&cached=0");
if (strlen($response)) {
file_put_contents("./har/$file.har", $response);
}
}
}
}
// clear the progress text
echo "\r \r";
echo "Done\r\n";
} else {
echo "No HAR files available for download\r\n";
}
} else {
echo "No tests found in results.txt\r\n";
}
/**
* Create a file name given an url
*
* @param mixed $results
*/
function BuildFileName($url)
{
$file = trim($url, "\r\n\t \\/");
$file = str_ireplace('http://', '', $file);
$file = str_ireplace(':', '_', $file);
$file = str_ireplace('/', '_', $file);
$file = str_ireplace('\\', '_', $file);
$file = str_ireplace('%', '_', $file);
return $file;
}