我在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?
这是为了未来的访客!
你可以得到php扩展“memcache”来在windows上使用memcached与php http://downloads.php.net/pierre/
Memcached是服务器守护进程,你可以在这里获取它的http://splinedancer.com/memcached-win32/
任何遇到使用memcached在Windows上工作的问题的人的注意事项。
根据评论,我假设您没有下载并安装memcached,但已成功安装了PHP的memcached模块。基本上,你已经拿到了车钥匙,但没有车。
memcached是为Linux而构建的,但它已被其他人移植到Windows。这个教程很旧,但它可能正是你要找的:http://www.codeforest.net/how-to-install-memcached-on-windows-machine
你的composer.json
应该有ext-memcached
列在其中,但它不会安装,如果它丢失,它只会抛出一个错误。以下是获取它的各种方法:
截至2018年的AFAIK没有用于PHP 7的JUST Memcached的二进制Windows端口但是在Laragon或者Winginx 中有一个预先打包的版本
有一个handful人在github上提供compiled DLLs(64位,并提供线程安全)
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
You can compile the php bindings但windows package of memcached已被打破4年(截至2018年)
这是一个围绕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;
}