memcachetest.php 542 B

123456789101112131415161718192021
  1. <?php
  2. $memcache = new Memcache;
  3. $memcache->connect('localhost', 11211) or die ("Could not connect");
  4. $version = $memcache->getVersion();
  5. echo "Server's version: ".$version."<br/>\n";
  6. $tmp_object = new stdClass;
  7. $tmp_object->str_attr = 'test';
  8. $tmp_object->int_attr = 123;
  9. $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
  10. echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
  11. $get_result = $memcache->get('key');
  12. echo "Data from the cache:<br/>\n";
  13. var_dump($get_result);
  14. ?>