Skip to content

Instantly share code, notes, and snippets.

@hataiit9x
Forked from maartendekeizer/test-memcached.php
Created March 14, 2022 08:01
Show Gist options
  • Save hataiit9x/1dfdf1599dfa9d687aed45c1736b68da to your computer and use it in GitHub Desktop.
Save hataiit9x/1dfdf1599dfa9d687aed45c1736b68da 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