search
HomeBackend DevelopmentPHP Tutorialmemcached 以及 php新客户端memcached 装配(参考)

memcached 以及 php新客户端memcached 安装(参考)

2010-02-23 11:05web2.0和web1.0不一样,web1.0以内容为中心,所以web1.0做负载只需缓存内容就可以了,使用反向代理缓存页面就可以解决大部分问题了。而web2.0鼓励用户交互,内容都是动态的,只做反向代理命的话中率低,而且对数据库进行频繁的写,对数据库压力大。所以,web2.0对 web1.0更需要使用内存缓存。memcached高性能的,分布式的内存对象缓存系统,在动态应用中减少数据库负载,提升访问速度。memcached已经被广泛应用在各种软件中,例如,nginx、mysql一、服务端安装使用weget下载libevent和memcachedlibevent: http://monkey.org/~provos/libevent-1.4.9-stable.tar.gzmemcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz1.先安装libeventtar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable  ./configure  make  make install  tar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable./configuremakemake install2.安装memcachedtar zxvf memcached-1.2.6.tar.gz  cd memcached-1.2.6  ./configure --enable-threads  make  make install  tar zxvf memcached-1.2.6.tar.gzcd memcached-1.2.6./configure --enable-threadsmakemake install注:如果启动时出现“memcached: error while loading shared libraries: libevent-1.4.so.2: cannot openshared object file: No such file or directory”之类的信息,表示memcached找不到libevent的位置所以,请先使用whereis libevent得到位置,然后连接到memcached所寻找的路径[[email&#160;protected] tools]# whereis libevent  libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a  [[email&#160;protected] tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less  [[email&#160;protected] tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/  二、php安装对memcached的支持php有两个版本的memcached客户端1.memcached这个是新版的客户端基于libmemcached,所以必须要安装libmemcached先安装libmemcached下载地址:http://download.tangent.org/libmemcached-0.26.tar.gz[[email&#160;protected] tools]# tar zxvf libmemcached-0.26.tar.gz  [[email&#160;protected] tools]# cd libmemcached-0.26  [[email&#160;protected] libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/  [[email&#160;protected] libmemcached-0.26]# make  [[email&#160;protected] libmemcached-0.26]# make install  [[email&#160;protected] tools]# tar zxvf libmemcached-0.26.tar.gz[[email&#160;protected] tools]# cd libmemcached-0.26[[email&#160;protected] libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/[[email&#160;protected] libmemcached-0.26]# make[[email&#160;protected] libmemcached-0.26]# make install安装php memcached及最新客户端下载地址:http://pecl.php.net/get/memcached[[email&#160;protected] tools]# tar zxvf memcached-0.1.4.tgz  [[email&#160;protected] tools]# cd memcached-0.1.4  [[email&#160;protected] memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/  [[email&#160;protected] memcached-0.1.4]# make  [[email&#160;protected] memcached-0.1.4]# make install  [[email&#160;protected] tools]# tar zxvf memcached-0.1.4.tgz[[email&#160;protected] tools]# cd memcached-0.1.4[[email&#160;protected] memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/[[email&#160;protected] memcached-0.1.4]# make[[email&#160;protected] memcached-0.1.4]# make install修改php.ini添加extension = "memcached.so"就可以了。1. checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located  checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located请先用whereis libmemcached找到路径,然后添加选项--with-libmemcached-dir=libmemcached路径2.memcache下载地址:http://pecl.php.net/get/memcache[[email&#160;protected] tools]# tar zxvf memcache-3.0.3.tgz [[email&#160;protected] tools]# cd memcache-3.0.3  [[email&#160;protected] tools]# /usr/local/php/bin/phpize  [[email&#160;protected] tools]# ./configure --with-php-config=/usr/local/php/bin/php-config  [[email&#160;protected] tools]# make  [[email&#160;protected] tools]# make install  [[email&#160;protected] tools]# tar zxvf memcache-3.0.3.tgz [[email&#160;protected] tools]# cd memcache-3.0.3[[email&#160;protected] tools]# /usr/local/php/bin/phpize[[email&#160;protected] tools]# ./configure --with-php-config=/usr/local/php/bin/php-config[[email&#160;protected] tools]# make[[email&#160;protected] tools]# make install修改php.ini添加extension = "memcache.so"就可以了。提示:如果php找不到so文件,请设置extension_dir。ps:这篇东西在草稿箱里呆很久了,最后还是决定把一篇分多篇发吧,这样感觉快多了。来源:http://willko.iteye.com/blog/332993NetSeek (2009-9-10 11:16:40)memcached 的客户端 libmemcached, 在处理value超过8k的数据时, 速度会直线下降, 在http://lists.tangent.org/piperma ... ovember/000484.html, 可以找到答案, 原因是libmemcached的buf太小了, 找到源文件memcached_constants.h, 修改#define MEMCACHED_MAX_BUFFER 8196, 改成合适的大小, 重新编译, 安装, 就可以了.libmemcached是C客户端库的接口到memcached服务器。它被设计为轻的内存使用情况,线程安全,并提供充分获得服务器端的方法。它还采用多种命令行工具: memcat , memflush , memrm , memstat ,并memslap (负载代)。图书馆一直在设计,让不同的散列方法对密钥,分割的钥匙,并使用统一的散列分配。 许可: BSD许可证(修订) 变化:修正递减的散列关键。修正的断言,是抓不好memset ( )调用的host_reset ( ) 。修正的一个问题,清除阻塞的I / O已经堆叠。增补memstat 。一种新的API冲水。 memcached简单的使用教程这是工程应用性质的文章:memcached是数据快速存取的工具,wikipedia和facebook就用了它提高速度。具体情况可以wiki.c/c++里面使用memcached本来是很简单的事情,但就是没有人说,非要我去读libmemcache的实例代码才行,manpage也没有说清楚(但还不得不看)。如果要使用memcached,步骤如下:1 安装memcached  你可以去官网上下载,也可以sudo apt-get install memcached2 测试你刚才的安装,  比如运行 memcached -d -m 64 -l 127.0.0.1 -p 12300  -d表示后台, -m 64表示使用64MB内存,-l 127.0.0.1 -p 12300 表示监听127.0.0.1:12300端口  没有任何消息就是运行成功3 安装libmemcached  这个就不要apt了,因为没有精确的libmemcached包,乖乖去官网下载吧。这个东西还需要libevent,这个没法apt,libevent安装的时候最好装到/usr/lib里面,不然libmemcached还不能运行。4 测试libmemcached  找一个文件比如test,然后运行memcp test --servers=127.0.0.1:12300  这样就把test拷贝到memcached管理的内存里面了。  memcat test --servers=127.0.0.1:12300  看看是不是刚才的那个文件。 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

Simple Guide: Sending Email with PHP ScriptSimple Guide: Sending Email with PHP ScriptMay 12, 2025 am 12:02 AM

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP Performance: Identifying and Fixing BottlenecksPHP Performance: Identifying and Fixing BottlenecksMay 11, 2025 am 12:13 AM

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

Dependency Injection for PHP: a quick summaryDependency Injection for PHP: a quick summaryMay 11, 2025 am 12:09 AM

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

Increase PHP Performance: Caching Strategies & TechniquesIncrease PHP Performance: Caching Strategies & TechniquesMay 11, 2025 am 12:08 AM

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.