File: expire.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 (69 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (5)
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
--TEST--
Memcached store, fetch & touch expired key
--XFAIL--
https://code.google.com/p/memcached/issues/detail?id=275
--SKIPIF--
<?php if (!extension_loaded("memcached")) print "skip";
if (!method_exists("memcached", "touch")) die ("skip memcached::touch is not available");
?>
--FILE--
<?php

include dirname (__FILE__) . '/config.inc';

function run_expiry_test ($m) {
	
	$key = uniqid ('will_expire_');
	
	$set = $m->set($key, "foo", 2);
	$v = $m->get($key);
	if (!$set || $v != 'foo') {
		echo "Error setting key to \"foo\" with 2s expiry.\n";
		return;
	}

	sleep(1);
	$res = $m->touch($key, 2);
	$v = $m->get($key);

	if(!$res || $v != 'foo') {
		echo "Error touching key for another 2s expiry.\n";
		var_dump($res);
		var_dump($m->getResultMessage());
		var_dump($v);
		return;
	}

	sleep(3);
	$v = $m->get($key);

	if ($v !== Memcached::GET_ERROR_RETURN_VALUE) {
		echo "Wanted:\n";
		var_dump(Memcached::GET_ERROR_RETURN_VALUE);
		echo "from get of expired value. Got:\n";
		var_dump($v);
		return;
	}
	echo "All OK" . PHP_EOL;
}

$m = memc_get_instance (array (
							Memcached::OPT_BINARY_PROTOCOL => true
						));

echo '-- binary protocol' . PHP_EOL;
run_expiry_test ($m);

$m = memc_get_instance ();

echo '-- text protocol' . PHP_EOL;
run_expiry_test ($m);

echo "DONE TEST\n";
?>
--EXPECT--
-- binary protocol
All OK
-- text protocol
All OK
DONE TEST