我在Windows 7中安装了memcached二进制文件并将其作为服务器启动。
当我输入wmic进程获取描述时,exetuablepath | findstr memcached.exe我得到了响应:命令行上的memcached.exe c: memcached memcached.exe。
当我尝试在php.net上运行示例代码时,我上了我的浏览器:
致命错误:第3行的C: DocumentRoot Framework index.php中找不到类"Memcache"调用堆栈:0.0010 335928 1. {main}()C: DocumentRoot Framework index.php:0
那么,我做错了什么呢? 我正在使用memcache.dll,因为我认为Windows不存在memcached.dll?
希望你已经启用了扩展!:)
我有..还是没有运气。 我应该下载哪个dll?
你确定扩展加载了吗? 检查phpinfo()并查看其是否已列出。
你有任何错误吗? 或者是在phpinfo中显示?
关于memcached,我在phpinfo中看不到任何内容。 我应该准确下载哪个.dll? Memcache和memcached让我很困惑!
检查apache错误日志以获取错误消息! dll应该遵循php所使用的相同编译器。 (VC9或VC6)顺便说一句,memcache.dll没问题
我安装了它。 在phpinfo中它说:memcache支持启用活动持久连接0版本2.2.6修订版本:修订版:296899 $但我仍然无法在php.net中运行代码
谢谢@Venu回答这个问题所以我可以接受。
@KorayTugay我发布了答案:)
由于你在标题中有memchached而在描述中有memcache,因此我认为它们是不同的技术
任何遇到使用memcached在Windows上工作的问题的人的注意事项。
对于初学者,请确保您拥有正确版本的memcached dll并且可以访问它。 http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/提供了广泛的选择,选择错误版本的memcached非常容易!
如果您运行的是PHP 5.5,则还需要php5.dll。你可以在这里得到这个
您可能需要编辑环境PATH设置,以便找到此dll。转到"我的电脑" - >"属性" - >"高级",然后单击"环境变量"以查看/编辑路径。如果您编辑它,则需要重新启动计算机。
确保已安装memcached服务器。按Ctrl + Alt + Del并检查memcached是否存在于您的服务列表中
如果不是,您需要*以管理员身份从Cmd提示安装它(从开始菜单中选择附件,单击命令提示符并选择以管理员身份运行)
c: pathtomemcached memcached.exe -d install
使用c:?? pathtomemcached memcached.exe -d start或net start"memcached Server"执行此操作。在我的安装上,前者不起作用
同样,我无法从任务管理器的"服务"选项卡启动memcached
能够在低级别使用memcached是很方便的,因此如果需要,启用telnet,并从命令提示符键入telnet。现在打开端口11211并尝试使用memcached
能够密切关注memcached中发生的事情也很有用。 phpMemCacheAdmin是迄今为止最好的工具
我认为这样:"选择错误的一个太容易了"可以在这个答案中加粗。由于选择了错误的版本,我整天都输了。我还要补充说,匹配86x / 64x WAMP和memcache.dll版本以及WAMP编译VC6 / VC9并匹配memcache.dll的VC6 / VC9版本非常重要。我有WAMP VC9,我使用的是memcache.dll VC6,这就是为什么它不起作用。
@Rob - 好点!我编辑了答案,并强调了答案的重要部分。
为了确定是使用线程安全还是非线程安全,这对我有所帮助:stackoverflow.com/a/5800346/470749
我对此非常困惑。 Memcached(带有d)和Memcache不是一回事。我在过去几个小时在线阅读的其他帖子表明,无法在Windows上安装Memcached(以d结尾)。你确定你有Memcached在Win上工作吗?它可以与PHP 7.0.1 x64线程安全一起使用吗?我一直在努力让它工作几个小时,但不断得到PHP Warning: PHP Startup: Unable to load dynamic library C:php-7.0.1-Win32-VC14-x64extphp_memcache.dll - The specified module could not be found.和/或Class Memcached not found。
不支持php 7.2?我看到5.5 - 5.6?
这是为了未来的游客!
检查phpinfo()并查看它是否已列出。
如果没有,请检查php.ini中是否启用了扩展,然后检查apache错误日志
错误信息! dll应该与php相同的编译器一致
是。 (VC9或VC6)顺便说一句,memcache.dll没问题
你可以获得php扩展"memcache"来在windows上使用memcached与php http://downloads.php.net/pierre/
Memcached是服务器守护进程,你可以在这里获取它的http://splinedancer.com/memcached-win32/
所有链接似乎都被打破了:|
根据评论,我假设您没有下载并安装memcached,但已成功安装了PHP的memcached模块。基本上,你已经拿到了车钥匙,但没有车。
memcached是为Linux而构建的,但它已被其他人移植到Windows。这个教程很旧,但它可能正是你要找的东西:http://www.codeforest.net/how-to-install-memcached-on-windows-machine
您的composer.json应该在其中列出ext-memcached但它不会安装,如果它丢失,它只会抛出一个错误。以下是获取它的各种方法:
Windows二进制路由
截至2018年的AFAIK没有用于PHP 7的JUST Memcached的二进制Windows端口
但Laragon或Winginx有一个预先打包的版本
Windows DLL路由
有一小部分人在github上提供编译的DLL(64位,并提供线程安全)
用于Linux路由的Windows子系统
ubuntu
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php-memcached
如果使用sudo service php7.2-fpm restart,请重启php fpm
从源路由编译
你可以编译php绑定但是memcached的windows包已经被打破了4年(截至2018年)
仅本地缓存文件Polyfill路由
这是一个围绕Memcached的脏包装程序,名为StaticCache,您可以在夹点中使用来从磁盘读取/写入值。它显然比memcached慢,所以它只是一个Windows开发的鞋子。如果您喜欢它,可以将其定义为具有相同名称的polyfill
function StaticCacheClear()
{
foreach (scandir(sys_get_temp_dir()) as $file) {
if (StringBeginsWith($file,"staticcache"))
{
$path = sys_get_temp_dir() ."/". $file;
unlink($path);
}
}
global $Memcache;
if ($Memcache) $Memcache->flush();
}
// REMOVE if you don't want a global way to clear cache
if (isset($_GET['clear_static_cache'])) {
StaticCacheClear();
}
function MemcacheGet($key)
{
global $Memcache;
$value = $Memcache ? $Memcache->get($key) : (file_exists($key)?file_get_contents($key):null);
return !$Memcache? $value : (Memcached::RES_NOTFOUND === $Memcache->getResultCode() ? null : $value);
}
function StaticCacheKey($key)
{
global $Memcache;
$cacheVersion ="MY_APP_VERSION_HERE";
$uniqueKey ="staticcache_{$key}_" . date("Ymd") ."$cacheVersion.cache";
$filename = sanitize_file_name($uniqueKey);
$filename = sys_get_temp_dir() . '/' . $filename;
return $Memcache ? $uniqueKey : $filename;
}
function StaticCacheWrite($key, $value)
{
global $Memcache;
if (isset($_GET['disable-cache'])) return null;
if ($Memcache)
$Memcache->set(StaticCacheKey($key), serialize($value));
else
file_put_contents(StaticCacheKey($key), serialize($value));
}
function StaticCacheRead($key)
{
global $Memcache;
$key = StaticCacheKey($key);
$value = MemcacheGet($key);
return $value !== null ? unserialize($value) : null;
}