title: How do you use memcache with PHP
body: <p>I finally got memcache running on my home pc so I can start developing with it at last!</p>
  
  <p>I am not off to a good start though I am trying to use the code on</p>
  
  <p><a href="http://www.php.net/manual/en/function.memcache-set.php" rel="noreferrer">php.net @ memcache-set</a> 
  I am unable to get either example code to work that they post</p>
  
  <p><strong>I tried this:</strong></p>
  
  <pre><code>&lt;?php
  /* procedural API */
  $memcache_obj = memcache_connect('memcache_host', 11211);
  memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);
  echo memcache_get($memcache_obj, 'var_key');
  ?&gt;
  </code></pre>
  
  <p><HR></p>
  
  <p><strong>And then</strong></p>
  
  <pre><code>&lt;?php
  /* OO API */
  $memcache_obj = new Memcache;
  $memcache_obj-&gt;connect('memcache_host', 11211);
  $memcache_obj-&gt;set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);
  echo $memcache_obj-&gt;get('var_key');
  ?&gt;
  </code></pre>
  
  <p><HR></p>
  
  <p><strong>And got these errors from the code above;</strong></p>
  
  <pre><code>Warning: Memcache::connect() [memcache.connect]: Can't connect to memcache_host:11211, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) in C:\webserver\htdocs\test\memcache\index.php on line 36
  
  Warning: Memcache::set() [memcache.set]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 42
  
  Warning: Memcache::get() [memcache.get]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 44
  </code></pre>
  
  <p><HR></p>
  
  <p><strong>I then found this code on the net somewhere and it does work</strong></p>
  
  <pre><code>&lt;?php
  $memcache = new Memcache;
  $memcache-&gt;connect('localhost', 11211) or die ("Could not connect");
  
  $tmp_object = new stdClass;
  $tmp_object-&gt;str_attr = 'test';
  $tmp_object-&gt;int_attr = 123;
  // add cache
  $memcache-&gt;set('key', $tmp_object, false, 30) or die ("Failed to save data at the server");
  echo "Store data in the cache (data will expire in 30 seconds)&lt;br/&gt;\n";
  // get cache
  $get_result = $memcache-&gt;get('key');
  echo "Data from the cache:&lt;br/&gt;\n";
  var_dump($get_result);
  ?&gt;
  </code></pre>
  
  <p><HR></p>
  
  <p><strong>How can I get the examples from PHP.net to work though?</strong></p>
  
  <hr>
  
  <p><strong>Also I would love to see any emample code involving memcache you might want to share I would really appreciate seeing some working examples</strong></p>