Commit 0906a9fc authored by Hannes Peterseim's avatar Hannes Peterseim
Browse files

adding memory parameter to the server + changed documentation

parent 64e5c245
......@@ -13,7 +13,13 @@ You can use it as a very fast in memory caching layer for small data of any type
##installation
Copy the server script (server.php) to an save place and run it as an service with "php server.php &".
Standard port will be 5000, but you can define an own port via "php server.php port &" the server listens only on 127.0.0.1:port.
Standard port will be 5000, but you can define an own port via "php server.php mode port memory &" the server listens only on 127.0.0.1:port.
####parameters :
mode : string version|help|listen (standard or if not given listen)
port : int between 450 and 65000 (pay attention for collisions with other used ports (netstat -tcu))
memory : int memory the ckript can use in MB
Do not forget to check the amount of memory a script can use, this defines the maximum size of the array the the data will be hold.
Copy the client script (client.php) to the place where you need it.
You can test everything with the supplied test script via "php test.php".
......@@ -53,8 +59,9 @@ stats();
array
with the following keys :
stores = number of stores
elements = number of elements overall
memory = memory usage in bytes
elements available = number of elements overall
memory overall = memory overall
memory used = memory usage in bytes
stores = detailed store data
####example
......
......@@ -66,6 +66,7 @@ class server
echo "\e[39minitializing standard memory store...";
$this->memMap[md5('standard')] = ['name' => 'standard', 'elements' => 0, 'values' => []];
echo "\e[32mok\n";
echo ini_get('memory_limit') . " memory can be used\n";
echo memory_get_usage(true) . " Bytes of memory allocated\n";
echo memory_get_usage() . " Bytes of memory used\n";
echo "\e[32mready to be used...\n";
......@@ -282,7 +283,7 @@ class server
$allStores++;
$stores[] = ['store' => $store['name'], 'elements' => $store['elements']];
}
return json_encode(['return' => 'ok', 'value' => ['stores available' => $allStores, 'elements available' => $allElements, 'memory used' => memory_get_usage(true), 'stores' => $stores]]);
return json_encode(['return' => 'ok', 'value' => ['stores available' => $allStores, 'elements available' => $allElements, 'memory possible' => ini_get('memory_limit') , 'memory used' => memory_get_usage(true), 'stores' => $stores]]);
}
/**
......@@ -459,7 +460,7 @@ class server
if (isset($_SERVER['argv'][1])) {
if ($_SERVER['argv'][1] == 'help') {
echo "php server.php mode port\n";
echo "mode : help|listen -> standard listen\n";
echo "mode : help||version|listen -> standard listen\n";
echo "port : int between 450 and 65000 -> standard 5000\n";
exit;
}
......@@ -471,8 +472,8 @@ if (isset($_SERVER['argv'][1])) {
}
}
if (isset($_SERVER['argv'][2])) {
if (!is_int($_SERVER['argv'][2]) || $_SERVER['argv'][2] < 450 || $_SERVER['argv'][2] > 65000) {
echo "\e[31mport " . $_SERVER[2] . " not possible\n";
if (!is_numeric(trim($_SERVER['argv'][2])) || (int) trim($_SERVER['argv'][2]) < 450 || (int) trim($_SERVER['argv'][2]) > 65000) {
echo "\e[31mport " . (int) trim($_SERVER['argv'][2]) . " not possible\n";
echo "\e[31mport should be int and between 450 and 65000\n";
}
}
......@@ -480,8 +481,12 @@ set_time_limit(0);
ob_implicit_flush();
$address = '127.0.0.1';
$port = 5000;
if (isset($_SERVER['argv'][2]) && is_int($_SERVER['argv'][2])) {
if (isset($_SERVER['argv'][2]) && is_numeric(trim($_SERVER['argv'][2]))) {
$port = $_SERVER['argv'][2];
}
if (isset($_SERVER['argv'][3]) && is_numeric(trim($_SERVER['argv'][3]))) {
ini_set('memory_limit', $_SERVER['argv'][3] . "M");
}
new server($address, $port);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment