File: compression_types.phpt

package info (click to toggle)
php-memcached 3.2.0%2B2.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,568 kB
  • sloc: ansic: 9,752; xml: 1,350; php: 478; pascal: 123; sh: 12; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download | duplicates (4)
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 include "skipif.inc";?>
--FILE--
<?php
include dirname (__FILE__) . '/config.inc';
$m = memc_get_instance ();

$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)