[英]How to install and use memcached in Windows for PHP?
我在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?
任何遇到使用memcached在Windows上工作的問題的人的注意事項。
根據評論,我假設您沒有下載並安裝memcached,但已成功安裝了PHP的memcached模塊。 基本上,你已經拿到了車鑰匙,但沒有車。
memcached是為Linux而構建的,但它已被其他人移植到Windows。 這個教程很舊,但它可能正是你要找的東西: http : //www.codeforest.net/how-to-install-memcached-on-windows-machine
這是為了未來的游客!
你可以獲得php擴展“memcache”來在windows上使用memcached與php http://downloads.php.net/pierre/
Memcached是服務器守護進程,你可以在這里獲取它的http://splinedancer.com/memcached-win32/
你的composer.json
應該在其中列出了ext-memcached
,但它不會安裝,如果它丟失,它只會拋出一個錯誤。 以下是獲取它的各種方法:
截至2018年的AFAIK沒有用於PHP 7的JUST Memcached的二進制Windows端口但是在Laragon或者Winginx中有一個預先打包的版本
有一小部分人在github上提供編譯的DLL (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
你可以編譯php綁定但是memcached的windows包已經被打破了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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.