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 638daec

Browse files
Add support if kvstorage in shmop
1 parent cddb0ea commit 638daec

File tree

3 files changed

+97
-9
lines changed

3 files changed

+97
-9
lines changed

‎bench.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,10 @@ function gethostname() {
790790
'37_02_php8_str_ccontains_simulate' => 100000,
791791
'38_01_php_uuid' => 1000000,
792792
'38_02_mod_uuid' => 1000000,
793-
'39_01_kvstorage_memory' => 1000000,
794-
'39_02_kvstorage_xcache' => 1000000,
795-
'39_03_kvstorage_apcu' => 1000000,
796-
'39_04_kvstorage_shmop' => 1000000,
793+
'39_01_kvstorage_memory' => 500000,
794+
'39_02_kvstorage_xcache' => 500000,
795+
'39_03_kvstorage_apcu' => 500000,
796+
'39_04_kvstorage_shmop' => 500000,
797797
);
798798
// Should not be more than X Mb
799799
// Different PHP could use different amount of memory
@@ -852,10 +852,10 @@ function gethostname() {
852852
'37_02_php8_str_ccontains_simulate' => 4,
853853
'38_01_php_uuid' => 4,
854854
'38_02_mod_uuid' => 4,
855-
'39_01_kvstorage_memory' => 4,
856-
'39_02_kvstorage_xcache' => 47,
857-
'39_03_kvstorage_apcu' => 93,
858-
'39_04_kvstorage_shmop' => 4,
855+
'39_01_kvstorage_memory' => 3,
856+
'39_02_kvstorage_xcache' => 2r,
857+
'39_03_kvstorage_apcu' => 47,
858+
'39_04_kvstorage_shmop' => 70,
859859
);
860860

861861
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1662,6 +1662,10 @@ function filter_out_name_by_pattern($key)
16621662
if (extension_loaded('apcu')) {
16631663
$has_apcu = "{$colorGreen}yes{$colorReset}";
16641664
}
1665+
$has_shmop = "{$colorYellow}no{$colorReset}";
1666+
if (extension_loaded('shmop')) {
1667+
$has_shmop = "{$colorGreen}yes{$colorReset}";
1668+
}
16651669
$has_eacc = "{$colorGreen}no{$colorReset}";
16661670
if (extension_loaded('eAccelerator')) {
16671671
$has_eacc = "{$colorYellow}yes{$colorReset}";
@@ -1765,7 +1769,7 @@ function print_results_common()
17651769
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
17661770
global $has_gd, $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
17671771
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1768-
global $has_apcu, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1772+
global $has_apcu, $has_shmop, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
17691773
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
17701774
global $colorGreen, $colorReset, $colorRed;
17711775

@@ -1802,6 +1806,7 @@ function print_results_common()
18021806
. str_pad("gd", $padInfo, '', STR_PAD_LEFT) . " : $has_gd: version: ". GD_VERSION."\n"
18031807
. str_pad("imagick", $padInfo, '', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION."\n"
18041808
. str_pad("apcu", $padInfo, '', STR_PAD_LEFT) . " : $has_apcu;\n"
1809+
. str_pad("shmop", $padInfo, '', STR_PAD_LEFT) . " : $has_shmop;\n"
18051810
. str_pad("-alternative->", $padInfo, '', STR_PAD_LEFT) . "\n"
18061811
. str_pad("igbinary", $padInfo, '', STR_PAD_LEFT) . " : $has_igb\n"
18071812
. str_pad("msgpack", $padInfo, '', STR_PAD_LEFT) . " : $has_msg\n"

‎kv-shmop.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_04_kvstorage_shmop()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-shmop.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-shmop.inc');
23+
if (!$kvstorage->available){
24+
return $emptyResult;
25+
}
26+
27+
$count = $testsLoopLimits['39_04_kvstorage_shmop'];
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-shmop.inc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Php 5.2+
4+
*/
5+
6+
class KVStorageShmop
7+
{
8+
public $available = false;
9+
public function __construct(){
10+
$this->available=true;
11+
if (!function_exists('shmop_open'))
12+
$this->available=false;
13+
if (!function_exists('shmop_write'))
14+
$this->available=false;
15+
if (!function_exists('shmop_read'))
16+
$this->available=false;
17+
if (!function_exists('shmop_size'))
18+
$this->available=false;
19+
if (!function_exists('shmop_close'))
20+
$this->available=false;
21+
}
22+
23+
public function set($key, $value, $timeout=60){
24+
$id=shmop_open($key, "a", 0, 0);
25+
$ret=shmop_write($id, $value, 0);
26+
shmop_close($id);
27+
return $ret;
28+
}
29+
30+
public function get($key, $default=null){
31+
$id=shmop_open($key, "a", 0, 0);
32+
$size=shmop_size($id);
33+
$ret=shmop_read($id,0,$size);
34+
shmop_close($id);
35+
return $ret;
36+
}
37+
38+
public function del($key){
39+
$id=shmop_open($key, "a", 0, 0);
40+
$ret=shmop_delete($id);
41+
shmop_close($id);
42+
return $ret;
43+
}
44+
}
45+
$kvstorage=new KVStorageXcache();

0 commit comments

Comments
(0)

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