运行WAMP服务器并启用了php_memcache扩展并尝试了代码
<?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);
?>
我收到了以下错误
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
答案 0 :(得分:4)
即使您正在使用WAMP,也需要将此行添加到php.ini文件中。 (我在:C:\ wamp \ bin \ php \ php5.3.10 \ php.ini)
extension=php_memcache.dll
如果您正在运行64位WAMP:
常用服务和扩展程序不适合您。
安装64位memcached服务:
http://s3.amazonaws.com/downloads.northscale.com/memcached-win64-1.4.4-14.zip
其中一个php扩展(与你的php版本相匹配):
Php 5.3:http://www.mediafire.com/download.php?o60feet9sw71six
PHP 5.4:http://www.mediafire.com/download.php?8d3vd26z3fg6bf1
答案 1 :(得分:1)
在PHP方面,memcache扩展提供了一些功能,因此PHP可以连接到memcached服务器。
但你必须:
在这里,您确定在本地计算机上安装了memcached服务器吗?
答案 2 :(得分:0)
尝试更改连接代码,如下所示
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
答案 3 :(得分:0)
这是我刚刚遵循的brill指南