Skip to content

Instantly share code, notes, and snippets.

@linuxpld
Forked from maartendekeizer/test-memcached.php
Created November 11, 2020 10:55
Show Gist options
  • Save linuxpld/660320642b25b1156a174438a898a307 to your computer and use it in GitHub Desktop.
Save linuxpld/660320642b25b1156a174438a898a307 to your computer and use it in GitHub Desktop.
Memcached test script
<?php
/**
* @license MIT License
* @copyright maartendekeizer
*/
$memcached = new Memcached();
$memcached->addServer('127.0.0.1', 11211);
$name = 'testkey';
$ttl = 10;
$data = sha1(time());
$memcached->set($name, $data, $ttl);
echo date('His') . ': key "' . $name . '" set to "' . $data . '" with ttl ' . $ttl . PHP_EOL;
for ($i = 0; $i < ($ttl + 5); $i ++) {
$res = $memcached->get($name);
echo date('His') . ': key "' . $name . '" data is "' . $res . '" and that is ' . ($res == $data ? 'a match' : 'not a match') . PHP_EOL;
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment