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 cddb0ea

Browse files
Add tests for kv apcu storage
1 parent ece4ca8 commit cddb0ea

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

‎bench.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
if (file_exists('kvstorage-xcache.inc') && extension_loaded('xCache')) {
114114
@include_once("kv-xcache.inc");
115115
}
116+
if (file_exists('kvstorage-apcu.inc') && extension_loaded('apcu')) {
117+
@include_once("kv-apcu.inc");
118+
}
119+
if (file_exists('kvstorage-shmop.inc') && extension_loaded('shmop')) {
120+
@include_once("kv-shmop.inc");
121+
}
116122
}// php>=5.0
117123

118124
if (extension_loaded('uuid')) {
@@ -786,6 +792,8 @@ function gethostname() {
786792
'38_02_mod_uuid' => 1000000,
787793
'39_01_kvstorage_memory' => 1000000,
788794
'39_02_kvstorage_xcache' => 1000000,
795+
'39_03_kvstorage_apcu' => 1000000,
796+
'39_04_kvstorage_shmop' => 1000000,
789797
);
790798
// Should not be more than X Mb
791799
// Different PHP could use different amount of memory
@@ -845,7 +853,9 @@ function gethostname() {
845853
'38_01_php_uuid' => 4,
846854
'38_02_mod_uuid' => 4,
847855
'39_01_kvstorage_memory' => 4,
848-
'39_02_kvstorage_xcache' => 4,
856+
'39_02_kvstorage_xcache' => 47,
857+
'39_03_kvstorage_apcu' => 93,
858+
'39_04_kvstorage_shmop' => 4,
849859
);
850860

851861
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1648,6 +1658,10 @@ function filter_out_name_by_pattern($key)
16481658
if (extension_loaded('apc')) {
16491659
$has_apc = "{$colorYellow}yes{$colorReset}";
16501660
}
1661+
$has_apcu = "{$colorYellow}no{$colorReset}";
1662+
if (extension_loaded('apcu')) {
1663+
$has_apcu = "{$colorGreen}yes{$colorReset}";
1664+
}
16511665
$has_eacc = "{$colorGreen}no{$colorReset}";
16521666
if (extension_loaded('eAccelerator')) {
16531667
$has_eacc = "{$colorYellow}yes{$colorReset}";
@@ -1751,7 +1765,7 @@ function print_results_common()
17511765
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
17521766
global $has_gd, $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
17531767
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1754-
global $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1768+
global $has_apcu, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
17551769
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
17561770
global $colorGreen, $colorReset, $colorRed;
17571771

@@ -1787,6 +1801,7 @@ function print_results_common()
17871801
. str_pad("-optional->", $padInfo, '', STR_PAD_LEFT) . "\n"
17881802
. str_pad("gd", $padInfo, '', STR_PAD_LEFT) . " : $has_gd: version: ". GD_VERSION."\n"
17891803
. str_pad("imagick", $padInfo, '', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION."\n"
1804+
. str_pad("apcu", $padInfo, '', STR_PAD_LEFT) . " : $has_apcu;\n"
17901805
. str_pad("-alternative->", $padInfo, '', STR_PAD_LEFT) . "\n"
17911806
. str_pad("igbinary", $padInfo, '', STR_PAD_LEFT) . " : $has_igb\n"
17921807
. str_pad("msgpack", $padInfo, '', STR_PAD_LEFT) . " : $has_msg\n"

‎kv-apcu.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 array/class interfaces
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_03_kvstorage_apcu()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-apcu.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-apcu.inc');
23+
if (!$kvstorage->available){
24+
return $emptyResult;
25+
}
26+
27+
$count = $testsLoopLimits['39_03_kvstorage_apcu'];
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Php 5.2+
4+
*/
5+
6+
class KVStorageApcu
7+
{
8+
public $available = false;
9+
public function __construct(){
10+
$this->available=true;
11+
if (!function_exists('apcu_store'))
12+
$this->available=false;
13+
if (!function_exists('apcu_fetch'))
14+
$this->available=false;
15+
if (!function_exists('apcu_delete'))
16+
$this->available=false;
17+
}
18+
19+
public function set($key, $value, $timeout=60){
20+
return apcu_store($key, $value, $timeout);
21+
}
22+
23+
public function get($key, $default=null){
24+
return apcu_exists($key)
25+
? apcu_fetch($key)
26+
: $default;
27+
}
28+
29+
public function del($key){
30+
return apcu_delete($key);
31+
}
32+
}
33+
$kvstorage=new KVStorageXcache();

‎kvstorage-xcache.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class KVStorageXcache
1717
}
1818

1919
public function set($key, $value, $timeout=60){
20-
return xcache_set($key, $value);
20+
return xcache_set($key, $value, $timeout);
2121
}
2222

2323
public function get($key, $default=null){

0 commit comments

Comments
(0)

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