-
Notifications
You must be signed in to change notification settings - Fork 6
/
smf_cache_test_get.php
159 lines (118 loc) · 3.78 KB
/
smf_cache_test_get.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
<?php
//
// An SMF utility to GET a file from cache, repeatedly, rapidly.
// Intended to help test race conditions, etc., behavior when making changes to smf caching.
// The goal should be for this to complete all requested executions without error.
//
// To use, copy both utilities to the forum root, where Settings.php is, & execute them simultaneously.
// Things are most interesting when you run at least two PUT scripts while running a GET script...
// Two PUTs at the same time trigger the race conditions that cause issues.
//
// ***** SMF 2.0 $ 2.1 *****
//
// Config section...
$file = 'nonimportantsettings';
$fields = 100; // how many fields in your json
$sleeptime = 10; // in milliseconds, between GETs
$reads = 1000; // don't go on forever...
// End config section
//*** Main program
doStartup();
loadSettings();
for ($i =1; $i <= $reads; $i++)
getfile($i);
doWrapUp();
return;
//*** Startup
function doStartup() {
global $rundir, $fp, $url, $board, $allTimer;
// Without this header, flushes don't work...
header( 'Content-type: text/html; charset=utf-8' );
echo("<br>********************************<br>");
echo("**** SMF rapid GET from cache ****<br>");
echo("********************************<br>");
define('SMF', 1);
define('SMF_VERSION', '2.1 RC2');
define('SMF_FULL_VERSION', 'SMF ' . SMF_VERSION);
define('MYSQL_TITLE', 'MySQL');
ini_set('display_errors', 1);
error_reporting(E_ALL);
@flush();
// Prime the pump...
$allTimer = microtime(true);
return;
}
//*** Settings File
function loadSettings() {
global $db_type, $db_connection, $db_prefix, $db_name, $smcFunc, $boardurl, $sourcedir, $cachedir, $modSettings;
global $cache_accelerator, $cache_enable, $cacheAPI;
$smcFunc = array();
// Load the settings...
require_once(dirname(__FILE__) . '/Settings.php');
// Get the database going!
if (empty($db_type) || $db_type == 'mysqli')
$db_type = 'mysql';
// Make the connection...
require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix);
// Load modSettings
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Load.php');
reloadSettings();
return;
}
//*** Read cache
function getFile($fileno) {
global $file, $fields, $size, $sleeptime, $sourcedir, $cacheAPI;
// Read from cache
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Load.php');
ini_set('display_errors', 1);
error_reporting(E_ALL);
$joe = cache_get_data($file);
// echo 'file: ' . $file . '<br>';
// echo 'data: ' . print_r($joe, TRUE) . '<br>';
if (is_null($joe))
{
echo 'NOT Successfully read file ' . $fileno . ' IS NULL...<br>';
}
elseif (count($joe) != $fields)
{
echo 'NOT Successfully read file ' . $fileno . ' incomplete: only ' . count($joe) . ' rows...<br>';
echo ' error: ' . print_r(error_get_last(), TRUE) . '<br>';
echo ' joe: ' . print_r($joe, TRUE) . '<br>';
}
else
echo 'Successfully read file ' . $fileno . '...<br>';
@flush();
// Pause briefly
usleep($sleeptime * 1000);
return;
}
//*** Wrap Up
function doWrapUp() {
global $allTimer;
echo "<br>Completed!<br><br>";
echo "<br>Elapsed time: " . timer($allTimer) . "<br><br>";
// Yes, both flushes necessary
@flush();
return;
}
//*** Timer - returns time from prior call as h:m:s:msec string
function timer(&$timer) {
$diff = abs(microtime(TRUE) - $timer);
$temp = (int) $diff; // get seconds (fraction is msec)
$msec = (int) (($diff - $temp) * 1000000);
$H = intdiv_alt($temp, 3600);
$temp = $temp % 3600;
$M = intdiv_alt($temp, 60);
$S = $temp % 60;
// Reset timer for next call...
$timer = microtime(TRUE);
return ($H . ":" . $M . ":" . $S . ":" . $msec);
}
// Crap, intdiv is only php 7+
function intdiv_alt($a, $b){
return ($a - $a % $b) / $b;
}
?>