如何解决memcache set方法总是失败的问题?
我在Windows 7上安装了XAMPP 1.7.3。PHP版本是5.3.1。我已从 http://www.splinedancer.com/memcached-win32。
我从 http://downloads.php.net/pierre 获得了 PHP 扩展 php_memcache.dll。
重新启动 apache 并检查 phpinfo() 显示 memcache 正常。
当我用下面的 PHP 页面测试它时。 set 方法总是失败。
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version." \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)\n";
$get_result = $memcache->get('key');
echo "Data from the cache: \n"
?>
set 方法总是返回 false,因此它不断输出
Server's version: Failed to save data at the server
I'm 卡住。我不知道用什么方法可以解决这个问题。 有人对可能的方向有任何想法吗?
谢谢。
I have XAMPP 1.7.3 installed on Windows 7. The PHP version is 5.3.1. I have successfully installed memcache for win32 from http://www.splinedancer.com/memcached-win32.
I got PHP extension php_memcache.dll from http://downloads.php.net/pierre.
Restarting apache and checking phpinfo() shows memcache is OK.
When I test it with below PHP page. It always fail in set method.
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version." \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)\n";
$get_result = $memcache->get('key');
echo "Data from the cache: \n"
?>
The set method always return false so it constantly output
Server's version: Failed to save data at the server
I'm stuck. I don't know which way to trouble shoot this issue.
Anybody has any idea about possible direction?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,首先要意识到我从未在 Windows 上使用过 Memcache。然而,phpinfo() 的东西肯定只是告诉你扩展没问题,而不是 memcache 本身......考虑到这一点,你确定它没有被防火墙什么的吗?检查 Windows 防火墙是否已禁用将是我的第一个“猜测”...
OK, first realise that I've never used Memcache on Windows. However, surely the phpinfo() stuff is just telling you that the extension is OK, not memcache itself... with that in mind, are you sure it's not being firewalled or something? Check that the Windows firewall is disabled would be my first 'guess'...
您收到任何 php 错误或警告吗?
你可以尝试
var_dump($memcache->getStats())
也尝试只将一些字符串写入内存缓存而不是该对象
并检查是否可以使用
telnet 127.0.0.1 11211
连接到该内存缓存如果没有任何帮助,请尝试使用不同的内存缓存服务器... Windows 防火墙不会阻止该端口吗?
do you get any php errors or warnings ?
you could try
var_dump($memcache->getStats())
also try writing just some string into memcache instead of that object
and check if you can connect to that memcache with
telnet 127.0.0.1 11211
if nothing helps try using a different server for memcache... doesn't windows firewall block that port ?