/
compression_types.phpt
76 lines (67 loc) · 2 KB
/
compression_types.phpt
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
--TEST--
Memcached compression test
--SKIPIF--
<?php if (!extension_loaded("memcached")) print "skip"; ?>
--FILE--
<?php
$m = new Memcached();
$m->addServer('localhost', 11211, 1);
$data = file_get_contents(dirname(__FILE__) . '/testdata.res');
function get_compression($name) {
switch (strtolower($name)) {
case 'zlib':
return Memcached::COMPRESSION_ZLIB;
case 'fastlz':
return Memcached::COMPRESSION_FASTLZ;
default:
echo "Strange compression type: $name\n";
return 0;
}
}
function fetch_with_compression($m, $key, $value, $set_compression = '', $get_compression = '') {
echo "set=[$set_compression] get=[$get_compression]\n";
if (!$set_compression) {
$m->setOption(Memcached::OPT_COMPRESSION, false);
} else {
$m->setOption(Memcached::OPT_COMPRESSION, true);
$m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($set_compression));
}
$m->set($key, $value, 1800);
if (!$get_compression) {
$m->setOption(Memcached::OPT_COMPRESSION, true);
} else {
$m->setOption(Memcached::OPT_COMPRESSION, true);
$m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($get_compression));
}
$value_back = $m->get($key);
var_dump($value === $value_back);
}
fetch_with_compression($m, 'hello1', $data, 'zlib', 'zlib');
fetch_with_compression($m, 'hello2', $data, 'zlib', 'fastlz');
fetch_with_compression($m, 'hello3', $data, 'fastlz', 'fastlz');
fetch_with_compression($m, 'hello4', $data, 'fastlz', 'zlib');
fetch_with_compression($m, 'hello5', $data, '', 'zlib');
fetch_with_compression($m, 'hello6', $data, '', 'fastlz');
fetch_with_compression($m, 'hello7', $data, 'zlib', '');
fetch_with_compression($m, 'hello8', $data, 'fastlz', '');
fetch_with_compression($m, 'hello9', $data, '', '');
?>
--EXPECT--
set=[zlib] get=[zlib]
bool(true)
set=[zlib] get=[fastlz]
bool(true)
set=[fastlz] get=[fastlz]
bool(true)
set=[fastlz] get=[zlib]
bool(true)
set=[] get=[zlib]
bool(true)
set=[] get=[fastlz]
bool(true)
set=[zlib] get=[]
bool(true)
set=[fastlz] get=[]
bool(true)
set=[] get=[]
bool(true)