搜索
首页后端开发php教程Windows下安装Memcached的步骤说明_PHP

memcache

(其实在Windows下安装还是比较简单的)

源码包准备:

1,memcached 1.2.1 for Win32 binaries

这个是 Win32 服务器端的 memcached 最新版本,直接下载就可以了;

2,php_memcache-5.2-Win32-vc6-x86-20090408.zip

这个是 php 所需的 PECL 扩展,即 php_memcache 扩展;(一定要和自己的 PHP 版本相同,我用的是5.2.1)

有了源码包包,那就开始大快朵颐吧,按照下面的步骤

1. 将第一个包解压放某个盘下面,比如在c:\memcached
2. 在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install' 安装
3. 再输入: ‘c:\memcached\memcached.exe -d start' 启动。(需要注意的: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了)
4. 解压第二个包包,里面会只有一个 php_memcache.dll 文件,把它放入 usr/local/php5/ext/ 中
5. 在C:\WINDOWS\php.ini 加入一行 ‘extension=php_memcache.dll'(不知道为什么 PHP 会有两个配置文件,一个在 usr/local/php5/php.ini, 而另一个则在 C:/WINDOWS/中,而且只改前一个配置文件不起作用,所以就把 WINDOWS 中的 php.ini 也改掉了!)

6,接着在 php.ini 文件里加上:
复制代码 代码如下:
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211

最好就放在刚才写 "extension=php_memcache.dll" 的下面。(这是默认的一些配置)
6.重新启动Apache,然后查看一下phpinfo,如果有 memcache 的说明,那么就说明安装成功啦!

试运行:

写一个 example.php 文件:(更多使用方法可以参看 PHP 手册里的 Memcache Functions 使用说明)
复制代码 代码如下: 


$memcache = new Memcache; 
$memcache->connect('localhost', 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"; 

var_dump($get_result); 

?>

如果有输出:
复制代码 代码如下:
Server's version: 1.4.5
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }

则说明,我们的 Memcached 已经正常运行啦! :~>

如果上面的地址不能下载,可以到http://www.splinedancer.com/memcached-win32/下载

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
高流量网站的PHP性能调整高流量网站的PHP性能调整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依赖注入:初学者的代码示例PHP中的依赖注入:初学者的代码示例May 14, 2025 am 12:08 AM

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

PHP性能:是否可以优化应用程序?PHP性能:是否可以优化应用程序?May 14, 2025 am 12:04 AM

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

PHP性能优化:最终指南PHP性能优化:最终指南May 14, 2025 am 12:02 AM

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

PHP依赖注入容器:快速启动PHP依赖注入容器:快速启动May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依赖注入与服务定位器PHP中的依赖注入与服务定位器May 13, 2025 am 12:10 AM

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

PHP性能优化策略。PHP性能优化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP电子邮件验证:确保正确发送电子邮件PHP电子邮件验证:确保正确发送电子邮件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具