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