1--TEST--
2Memcached store, fetch & touch expired key
3--SKIPIF--
4<?php
5$min_version = "1.4.8";
6include dirname(__FILE__) . "/skipif.inc";
7if (!method_exists("memcached", "touch")) die ("skip memcached::touch is not available");
8if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
9?>
10--FILE--
11<?php
12
13include dirname (__FILE__) . '/config.inc';
14
15function run_expiry_test ($m) {
16
17	$key = uniqid ('will_expire_');
18
19	$set = $m->set($key, "foo", 2);
20	$v = $m->get($key);
21	if (!$set || $v != 'foo') {
22		echo "Error setting key to \"foo\" with 2s expiry.\n";
23		return;
24	}
25
26	sleep(1);
27	$res = $m->touch($key, 2);
28	$v = $m->get($key);
29
30	if(!$res || $v != 'foo') {
31		echo "Error touching key for another 2s expiry.\n";
32		var_dump($res);
33		var_dump($m->getResultMessage());
34		var_dump($v);
35		return;
36	}
37
38	sleep(3);
39	$v = $m->get($key);
40
41	if ($v !== Memcached::GET_ERROR_RETURN_VALUE) {
42		echo "Wanted:\n";
43		var_dump(Memcached::GET_ERROR_RETURN_VALUE);
44		echo "from get of expired value. Got:\n";
45		var_dump($v);
46		return;
47	}
48	echo "All OK" . PHP_EOL;
49}
50
51$m = memc_get_instance (array (
52							Memcached::OPT_BINARY_PROTOCOL => true
53						));
54
55echo '-- binary protocol' . PHP_EOL;
56run_expiry_test ($m);
57
58$m = memc_get_instance ();
59
60echo '-- text protocol' . PHP_EOL;
61run_expiry_test ($m);
62
63echo "DONE TEST\n";
64?>
65--EXPECT--
66-- binary protocol
67All OK
68-- text protocol
69All OK
70DONE TEST
71