Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5a8808

Browse files
First try memcache and redis storage tests
1 parent 6a9a9c9 commit e5a8808

File tree

10 files changed

+244
-3
lines changed

10 files changed

+244
-3
lines changed

‎bench.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@
119119
if (file_exists('kvstorage-shmop.inc') && extension_loaded('shmop')) {
120120
@include_once("kv-shmop.inc");
121121
}
122+
if (file_exists('kvstorage-memcache.inc') && extension_loaded('memcache')) {
123+
@include_once("kv-memcache.inc");
124+
}
125+
if (file_exists('kvstorage-redis.inc') && extension_loaded('redis')) {
126+
@include_once("kv-redis.inc");
127+
}
122128
}// php>=5.0
123129

124130
if (extension_loaded('uuid')) {
@@ -794,6 +800,8 @@ function gethostname() {
794800
'39_02_kvstorage_xcache' => 500000,
795801
'39_03_kvstorage_apcu' => 500000,
796802
'39_04_kvstorage_shmop' => 500000,
803+
'39_05_kvstorage_memcache' => 500000,
804+
'39_06_kvstorage_redis' => 500000,
797805
);
798806
// Should not be more than X Mb
799807
// Different PHP could use different amount of memory
@@ -853,9 +861,11 @@ function gethostname() {
853861
'38_01_php_uuid' => 4,
854862
'38_02_mod_uuid' => 4,
855863
'39_01_kvstorage_memory' => 3,
856-
'39_02_kvstorage_xcache' => 2r,
864+
'39_02_kvstorage_xcache' => 2,
857865
'39_03_kvstorage_apcu' => 47,
858866
'39_04_kvstorage_shmop' => 70,
867+
'39_05_kvstorage_memcache' => 4,
868+
'39_06_kvstorage_redis' => 4,
859869
);
860870

861871
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1666,6 +1676,22 @@ function filter_out_name_by_pattern($key)
16661676
if (extension_loaded('shmop')) {
16671677
$has_shmop = "{$colorGreen}yes{$colorReset}";
16681678
}
1679+
$has_memcache = "{$colorYellow}no{$colorReset}";
1680+
if (extension_loaded('memcache')) {
1681+
$has_memcache = "{$colorGreen}yes{$colorReset}";
1682+
include_once('memcache.inc');
1683+
$v=get_memcached_version();
1684+
if ($v) define('MEMCACHE_VERSION',$v);
1685+
else define('MEMCACHE_VERSION','-.-.-');
1686+
}
1687+
$has_redis = "{$colorYellow}no{$colorReset}";
1688+
if (extension_loaded('memcache')) {
1689+
$has_redis = "{$colorGreen}yes{$colorReset}";
1690+
include_once('redis.inc');
1691+
$v=get_redis_version();
1692+
if ($v) define('REDIS_VERSION',$v);
1693+
else define('REDIS_VERSION','-.-.-');
1694+
}
16691695
$has_eacc = "{$colorGreen}no{$colorReset}";
16701696
if (extension_loaded('eAccelerator')) {
16711697
$has_eacc = "{$colorYellow}yes{$colorReset}";
@@ -1769,7 +1795,7 @@ function print_results_common()
17691795
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
17701796
global $has_gd, $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
17711797
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1772-
global $has_apcu, $has_shmop, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1798+
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
17731799
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
17741800
global $colorGreen, $colorReset, $colorRed;
17751801

@@ -1807,6 +1833,8 @@ function print_results_common()
18071833
. str_pad("imagick", $padInfo, '', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION."\n"
18081834
. str_pad("apcu", $padInfo, '', STR_PAD_LEFT) . " : $has_apcu;\n"
18091835
. str_pad("shmop", $padInfo, '', STR_PAD_LEFT) . " : $has_shmop;\n"
1836+
. str_pad("memcache", $padInfo, '', STR_PAD_LEFT) . " : $has_memcache, version: ".MEMCACHE_VERSION.";\n"
1837+
. str_pad("redis", $padInfo, '', STR_PAD_LEFT) . " : $has_redis, version: ".REDIS_VERSION.";\n"
18101838
. str_pad("-alternative->", $padInfo, '', STR_PAD_LEFT) . "\n"
18111839
. str_pad("igbinary", $padInfo, '', STR_PAD_LEFT) . " : $has_igb\n"
18121840
. str_pad("msgpack", $padInfo, '', STR_PAD_LEFT) . " : $has_msg\n"

‎kv-memcache.inc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod memcache
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_04_kvstorage_memcache()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-memcache.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-memcache.inc');
23+
if (!$kvstorage->available){
24+
return $emptyResult;
25+
}
26+
27+
$count = $testsLoopLimits['39_04_kvstorage_memcache'];
28+
$time_start = get_microtime();
29+
30+
for ($i = 0; $i < $count; $i++) {
31+
$num = $i / 100.;
32+
$kvstorage->set($i, $num);
33+
$v=$kvstorage->get($i);
34+
if ($v===$num) $kvstorage->del($i);
35+
}
36+
$totalOps += $count;
37+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
38+
}

‎kv-redis.inc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod redis
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_05_kvstorage_redis()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-redis.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-redis.inc');
23+
if (!$kvstorage->available){
24+
return $emptyResult;
25+
}
26+
27+
$count = $testsLoopLimits['39_05_kvstorage_redis'];
28+
$time_start = get_microtime();
29+
30+
for ($i = 0; $i < $count; $i++) {
31+
$num = $i / 100.;
32+
$kvstorage->set($i, $num);
33+
$v=$kvstorage->get($i);
34+
if ($v===$num) $kvstorage->del($i);
35+
}
36+
$totalOps += $count;
37+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
38+
}

‎kvstorage-apcu.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ class KVStorageApcu
3030
return apcu_delete($key);
3131
}
3232
}
33-
$kvstorage=new KVStorageXcache();
33+
$kvstorage=new KVStorageApcu();

‎kvstorage-memcache.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Php 5.2+
4+
*/
5+
6+
class KVStorageMemcache
7+
{
8+
public $available = false;
9+
private $object=null;
10+
public function __construct(){
11+
$this->available=true;
12+
if (!class_exists('Memcache'))
13+
$this->available=false;
14+
include('memcache.inc');
15+
$this->object=get_memcached_object();
16+
}
17+
18+
public function set($key, $value, $timeout=60){
19+
return $this->object->set($key, $value,0, $timeout);
20+
}
21+
22+
public function get($key, $default=null){
23+
return $this->object->get($key);
24+
}
25+
26+
public function del($key){
27+
return $this->object->delete($key);
28+
}
29+
}
30+
$kvstorage=new KVStorageMemcache();

‎kvstorage-redis.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Php 5.2+
4+
*/
5+
6+
class KVStorageRedis
7+
{
8+
public $available = false;
9+
private $object=null;
10+
public function __construct(){
11+
$this->available=true;
12+
if (!class_exists('Redis'))
13+
$this->available=false;
14+
include('redis.inc');
15+
$this->object=get_redis_object();
16+
}
17+
18+
public function set($key, $value, $timeout=60){
19+
return $this->object->set($key, $value,0, $timeout);
20+
}
21+
22+
public function get($key, $default=null){
23+
return $this->object->get($key);
24+
}
25+
26+
public function del($key){
27+
return $this->object->expire($key,0);
28+
}
29+
}
30+
$kvstorage=new KVStorageRedis();

‎memcache-conn.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[memcached]
2+
host = localhost
3+
port = 11211

‎memcache.inc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* php -mod-memcache test/generic functions
4+
*/
5+
6+
/** ---------------------------------- Tests functions -------------------------------------------- */
7+
8+
function get_memcache_object()
9+
{
10+
$cfg = array(
11+
'host'=>'localhost',
12+
'port'=>11211
13+
);
14+
if (is_file('memcached-conn.ini')){
15+
$cfg=parse_ini_file('memcached-conn.ini');
16+
}
17+
static $m=null;
18+
if ($m===null)
19+
$m = new Memcache;
20+
if ($m->connect($cfg['host'], $cfg['port']))
21+
return $m;
22+
return false;
23+
}
24+
25+
function get_memcached_version()
26+
{
27+
$m = get_memcache_object();
28+
if ($m)
29+
return $m->getVersion();
30+
return false;
31+
}

‎redis-conn.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[redis]
2+
host = localhost
3+
port = 6379
4+
connectTimeout = 1.0
5+
database = 2
6+
auth =

‎redis.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* php -mod-memcache test/generic functions
4+
*/
5+
6+
/** ---------------------------------- Tests functions -------------------------------------------- */
7+
8+
function get_redis_object()
9+
{
10+
$cfg = array(
11+
'host'=>'localhost',
12+
'port'=>6379,
13+
'database'=>2,
14+
);
15+
if (is_file('redis-conn.ini')){
16+
$cfg=parse_ini_file('redis-conn.ini');
17+
}
18+
static $r=null;
19+
if ($r===null)
20+
$r = new Redis;
21+
if ($r->connect($cfg['host'], $cfg['port'])){
22+
$r->swapdb(0, (int)$cfg['database']);
23+
return $r;
24+
}
25+
return false;
26+
}
27+
28+
function get_redis_version()
29+
{
30+
$r = get_redis_object();
31+
if ($r){
32+
$info = $r->info('server');
33+
// print_r($info);
34+
return $info['redis_version'];
35+
}
36+
return false;
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /