forked from SimonSimCity/PhpSpeed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtests4.php
371 lines (311 loc) · 11.6 KB
/
runtests4.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/***************************************************************************
*
* PHPspeed.com | PHP Benchmarking Script
* http://www.phpspeed.com
* November 4, 2006
*
* This is a commercial script. You MAY modify this script for your
* personal use. You MAY NOT redistrubute modified code without the
* written permission of the author. Please see the included license
* for additional restrictions.
*
***************************************************************************/
define('IN_PHPSPEED', true);
include "config_db.php";
include "inc/mysql.php";
include "inc/functions.server.php";
$self = $_SERVER['PHP_SELF'];
$db = new sql_db($dbhost, $dbuname, $dbpass, $dbname, false);
if(!$db->db_connect_id)
{
message_die(CRITICAL_ERROR, "Could not connect to the database");
}
$sql = "SELECT * FROM phpspeed_config";
$result = $db->sql_query($sql);
$ver = mysql_fetch_assoc($result);
$tests_run = $ver['tests_run'];
$new_tests = ($tests_run + 1);
session_start();
if (isset($_GET['action']) and $_GET['action'] == 'logout') {
session_start();
session_destroy();
header("Location: $self");
}
if(isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
$login = "<a href=\"$self?action=logout\"><img align=\"middle\" src=\"inc/images/exit.gif\" border=\"0\" hspace=\"6\" alt=\"logout\"></a>";
} else {
$login = "<span class=\"gen\"><form name=\"login\" action=\"$self\" method=\"POST\" style=\"margin:0;\"><input type=\"hidden\" name=\"submit\">Name: <input type=\"text\" name=\"user\" size=\"10\" class=\"post\"> Pass: <input type=\"password\" name=\"pass\" size=\"10\" class=\"post\"> <input name=\"Submit\" type=\"submit\" class=\"button\" value=\"Login\"></form></span>";
}
$u = isset($_POST['user']) ? $_POST['user'] : ''; //username from form
$p = isset($_POST['pass']) ? $_POST['pass'] : ''; // password from form.
if ($u == "$admin" && $p == "$pass"){
$_SESSION['user'] = $u;
$_SESSION['logged'] = "yes";
header("Location: $self");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHPspeed | <?php echo $_SERVER['HTTP_HOST']; ?></title>
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="start" title="Home" href="http://www.phpspeed.com/" />
<link rel="stylesheet" type="text/css" media="screen" href="inc/Style.css" />
</head>
<body>
<table width="97%" cellspacing="0" cellpadding="15" border="0" align="center">
<tr>
<td>
<span class="maintitle">PHPspeed <?php echo $ver['version']; ?></span><br />
<span class="mainmenu"><a href="index.php">Home</a> •
<a href="phpinfo.php">PHP Info</a> •
<a href="mysql.php">MySQL Info</a> •
<a href="info.php">System Info</a></span>
</td>
<td align="right">
<?php echo $login; ?>
</td>
</tr>
</table>
<?php
ignore_user_abort(TRUE);
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush(1);
define('CSV_SEP', ',');
define('CSV_NL', "\n");
define('DEFAULT_BASE', 500);
define('MIN_BASE', 5);
////define('DEFAULT_BASE', 2000);
//define('MIN_BASE', 50);
$TESTS_DIRS = array('tests4');
$test = isset($_GET['test']) ? htmlentities(addslashes($_GET['test'])) : '';
if ($test != 'go') {
echo "
<H6> Benchmark # 4 | Real World PHP Test</h6>
<table width=\"94%\" cellpadding=\"10\" cellspacing=\"1\" align=\"center\" class=\"forumline\">
<tr>
<td class=\"row2\">
This benchmark measures the time to load 4 PHP pages of various sizes. There are no database pulls in this benchmark,
this test will measure the real world time for someone to load a PHP page on your server. Real World tests are one of the most
important ways to measure your server performance as they indicate how long someone has to wait for your server to serve them a page.
The test pages vary in detail to simulate a real environment. If you have a cacheing system in place on your site, you will see
large fluctuations from the first test to the following tests due to cacheing after the first page load. Depending on your purpose
for running this benchmark, you might run tests with cacheing off to see the benefit of some tweaks.<br /><br />
<u>Testing Guidelines:</u>
<li>Always run tests when your server is least busy</li>
<li>Run each test several times and take the best score</li>
<li>Remember to write down any tweaks you make and the date</li>
<br /><br />
The tests are each run multiple times and the average of each, along with the total is
returned. Upon completion you can save your results so that after you make tweaks you
can compare between tests.<br /><br />
To begin this test click <a href=\"runtests4.php?test=go\">» here</a>
</td>
</tr>
</table>
";
} else {
if(isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
//**** This is the output for the test name below
function test_start($func) {
global $GLOBAL_TEST_FUNC;
global $GLOBAL_TEST_START_TIME;
$GLOBAL_TEST_FUNC = $func;
echo "<b>" . sprintf('%34s', $func) . "</b> ... \t";
flush();
list($usec, $sec) = explode(' ', microtime());
$GLOBAL_TEST_START_TIME = $usec + $sec;
}
//**** This is the output for the test time below
function test_end($func) {
global $GLOBAL_TEST_FUNC;
global $GLOBAL_TEST_START_TIME;
list($usec, $sec) = explode(' ', microtime());
$now = $usec + $sec;
if ($func !== $GLOBAL_TEST_FUNC) {
trigger_error('Wrong func: [' . $func . '] ' .
'vs ' . $GLOBAL_TEST_FUNC);
return FALSE;
}
if ($now < $GLOBAL_TEST_START_TIME) {
trigger_error('Wrong func: [' . $func . '] ' .
'vs ' . $GLOBAL_TEST_FUNC);
return FALSE;
}
$duration = $now - $GLOBAL_TEST_START_TIME;
echo sprintf('%9.04f', $duration) . ' seconds' . " | \n";
return $duration;
}
function test_regression($func) {
trigger_error('* REGRESSION * [' . $func . ']' . "\n");
die();
}
function do_tests($base, &$tests_list, &$results) {
foreach ($tests_list as $test) {
$results[$test] = call_user_func($test, $base, $results);
}
}
function load_test($tests_dir, &$tests_list) {
if (($dir = @opendir($tests_dir)) === FALSE) {
return FALSE;
}
$matches = array();
while (($entry = readdir($dir)) !== FALSE) {
if (preg_match('/^(test_.+)[.]php$/i', $entry, $matches) <= 0) {
continue;
}
$test_name = $matches[1];
include_once($tests_dir . '/' . $entry);
flush();
if (!function_exists($test_name . '_enabled')) {
echo 'INVALID !' . "\n";
continue;
}
if (call_user_func($test_name . '_enabled') !== TRUE) {
echo 'disabled.' . "\n";
continue;
}
if (!function_exists($test_name)) {
echo 'BROKEN !' . "\n";
continue;
}
array_push($tests_list, $test_name);
}
closedir($dir);
return TRUE;
}
function load_tests(&$tests_dirs, &$tests_list) {
$ret = FALSE;
foreach ($tests_dirs as $tests_dir) {
if (load_test($tests_dir, $tests_list) === TRUE) {
$ret = TRUE;
}
}
if (count($tests_list) <= 0) {
return FALSE;
}
asort($tests_list);
return $ret;
}
function csv_escape($str) {
if (strchr($str, CSV_SEP) !== FALSE) {
return '"' . str_replace('"', '\'', $str) . '"';
}
return $str;
}
function export_csv($csv_file, &$results, &$percentile_times) {
if (empty($csv_file)) {
return TRUE;
}
if (($fp = fopen($csv_file, 'w')) === FALSE) {
return FALSE;
}
if (fputs($fp, csv_escape('Test') . CSV_SEP . csv_escape('Time') . CSV_SEP .
csv_escape('Percentile') . CSV_NL)
=== FALSE) {
@fclose($fp);
unlink($csv_file);
return FALSE;
}
foreach ($results as $test => $time) {
if (fputs($fp, csv_escape($test) . CSV_SEP .
csv_escape(sprintf('%.04f', $time)) . CSV_SEP .
csv_escape(sprintf('%.03f', $percentile_times[$test])) .
CSV_NL) === FALSE) {
@fclose($fp);
unlink($csv_file);
return FALSE;
}
}
if (fclose($fp) === FALSE) {
return FALSE;
}
return TRUE;
}
function show_summary($base, &$results, $csv_file) {
$total_time = 0.0;
foreach ($results as $test => $time) {
$total_time += $time;
}
if ($total_time <= 0.0) {
die('Not enough iterations, please try with more.' . "\n");
}
$percentile_times = array();
foreach ($results as $test => $time) {
$percentile_times[$test] = $time * 100.0 / $total_time;
}
$score = (float) $base * 90 / $total_time;
//Insert into DB
global $db, $dbhost, $dbuname, $dbpass, $dbname, $ver, $cpu_info, $uptime, $tot_mem, $percent_used, $new_tests;
$result = $db->sql_query("INSERT INTO results4
VALUES ('','" . time() . "','$cpu_info','$uptime','" . round(($tot_mem/1024),2) . " GB - $percent_used % Used','{$ver['version']}','" . phpversion() . "','" . mysql_get_server_info() . "','" . $_SERVER['SERVER_SOFTWARE'] . "','" . serialize($results) . "','" . count($results) . "','$base','" . round($total_time) . "','" . round($score) . "','" . $_SERVER['HTTP_HOST'] . "')");
$result2 = $db->sql_query("UPDATE phpspeed_config SET tests_run ='$new_tests', last_test = " . time() . "");
echo
'<br /><br />Tests : ' . count($results) . "\n" .
'<br />Iterations : ' . $base . "\n" .
'<br />Total time : ' . round($total_time) . ' seconds' . "\n" .
'<br />Score : ' . round($score) . ' (higher is better)' . "\n";
if ($csv_file !== FALSE) {
export_csv($csv_file, $results, $percentile_times);
}
}
$base = DEFAULT_BASE;
$csv_file = FALSE;
////
if (function_exists('getopt')) {
$options = getopt('f:hi:');
} else {
$options = array();
}
////
if (!empty($options['f'])) {
$csv_file = $options['f'];
if (preg_match('/[.]csv$/i', $csv_file) <= 0) {
$csv_file .= '.csv';
}
}
if (!empty($options['i']) && is_numeric($options['i'])) {
$base = $options['i'];
}
if ($base < MIN_BASE) {
die('Min iterations = ' . MIN_BASE . "\n");
}
echo '<h6> Performing the benchmark. Please be patient while the tests are conducted</h6>';
echo "<div class=\"testoutput\"><div class=\"testoutputtext\">";
if (function_exists('phpversion')) {
echo 'PHP version: ' . phpversion() . "<br />\n";
}
echo 'MySQL version: ' . mysql_get_server_info() . "<br />\n";
echo 'Server Software: ' . $_SERVER['SERVER_SOFTWARE'] . "<br />\n";
echo 'Date : ' . date('F j, Y, g:i a') . "<br /><br />\n";
$tests_list = array();
$results = array();
if (load_tests($TESTS_DIRS, $tests_list) === FALSE) {
die('Unable to load tests');
}
echo "\n";
do_tests($base, $tests_list, $results);
echo "\n";
show_summary($base, $results, $csv_file);
echo "<br /><a href=\"runtests4.php?test=go\">Run again</a> | <a href=\"benchhistory.php?bench=4\">» Test history</a></div></div>\n";
} else {
echo "<table width=\"95%\" align=\"center\">
<tr>
<td width=\"100%\">
<table class=\"forumline\" cellpadding=\"8\">
<tr>
<td class=\"row1\">You need to login to view this page...</td>
</tr>
</table>
</td>
</tr>
</table>";
}
}
?>
</div>
</body>
</html>