forked from cubiclesoft/php-license-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurrency_test.php
115 lines (87 loc) · 2.56 KB
/
concurrency_test.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
<?php
// License server concurrency testing module. Requires PHP concurrency tester.
// (C) 2021 CubicleSoft. All Rights Reserved.
if (!isset($_SERVER["argc"]) || !$_SERVER["argc"])
{
echo "This file is intended to be run from the command-line.";
exit();
}
if ($argc < 2)
{
echo "Syntax: concurrency_test.php StartAtTimestamp\n\n";
echo "This program is usually run via PHP concurrency tester. Running tests as a single process, please wait...\n\n";
$argv[1] = time() - 1;
}
// Wait until the start time.
$diff = ((double)$argv[1] - microtime(true));
if ($diff > 0) usleep($diff * 1000000);
// Temporary root.
$rootpath = str_replace("\\", "/", dirname(__FILE__));
require_once $rootpath . "/support/sdk_license_server.php";
require_once $rootpath . "/support/random.php";
$rng = new CSPRNG();
$lsrv = new LicenseServer();
// Create a temporary product, major version, and license.
$result = $lsrv->Connect();
if (!$result["success"])
{
var_dump($result);
exit();
}
$result = $lsrv->CreateProduct("Test " . microtime(true));
if (!$result["success"])
{
var_dump($result);
exit();
}
$pid = $result["id"];
$result = $lsrv->SetMajorVersion($pid, 1);
if (!$result["success"])
{
var_dump($result);
exit();
}
$options = array(
"expires" => false,
"date" => time(),
"product_class" => 0,
"minor_ver" => 0,
"custom_bits" => 0,
"info" => array(
"quantity" => 1
)
);
$result = $lsrv->CreateLicense($pid, 1, "[email protected]", $options);
if (!$result["success"])
{
var_dump($result);
exit();
}
$serialnum = $result["serial_num"];
$numverifyerrors = 0;
$numverified = 0;
$numactivated = 0;
$startts = microtime(true);
do
{
// Simulate new localhost connections by sleeping.
// Creating real connections rapidly starves the OS of TCP/IP socket handles.
usleep($rng->GetInt(500, 1800));
// 1 in 20 chance of performing an activation.
$activate = ($rng->GetInt(1, 20) == 1);
//$activate = true;
$result = $lsrv->VerifySerial($serialnum, $pid, 1, "[email protected]", ($activate ? "activate" : false));
if (!$result["success"]) $numverifyerrors++;
else
{
$numverified++;
if ($activate) $numactivated++;
}
$diff = microtime(true) - $startts;
} while ($diff < 10);
// Remove the product.
$lsrv->DeleteProduct($pid);
// Output results.
if ($argc < 2) echo "verified_per_sec,activated_per_sec,num_verified,num_activated,verify_errors\n";
echo ($numverified / $diff) . "," . ($numactivated / $diff) . "," . $numverified . "," . $numactivated . "," . $numverifyerrors . "\n";
?>