tags:

views:

674

answers:

2

Hi

Iam running WAMP server and just enabled php_memcache extension and have tried the code

<?php

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);

?>

and i got the following error

Notice: Memcache::connect() [memcache.connect]: Server localhost (tcp 11211) failed with: 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:\wamp\www\memcache\test1.php on line 4

Warning: Memcache::connect() [memcache.connect]: Can't connect to localhost: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:\wamp\www\memcache\test1.php on line 4
Could not connect
A: 

Try changing your connecting codes as follows

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
SpawnCxy
A: 

The memcache extension, on the PHP side of things, provides function so PHP can connect to a memcached server.

But you have to :

  • install such a server (or several or them, as memcached works as a cluster of servers)
  • start it
  • configure it : mainly, indicate
    • how much memory it can use,
    • on each port it listens to connections

Here, are you sure that you installed a memcached server on your local machine ?

Pascal MARTIN
If he didn't then the program should die with "Could not connect",is that right? :)
SpawnCxy
It did die with *Could not connect*, did it not ? *(see the last line of the error, after the notice and the warning)*
Pascal MARTIN
...Oh,you're right.I met this problem before and I solved it as my answer said.Just a little curious he didn't pick my answer.
SpawnCxy