ÔÚ¡¶phper¡·µç×ÓÔÓÖ¾µÄµÚÒ»ÆÚÖУ¬ÓкÚҹ·ÈËдµÄ¹ØÓÚMemcacheµÄÏêϸ°²×°½Ì³Ì£¬±¾ÈËÔÚubuntuÉÏ°²×°ÍêÔËÐеÄʱºò±¨´í£º
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
°´ÕÕ£º¡¶libeven¡¢memcached¡¢libmemcache°²×°¡·Öеķ½·¨£¬Ê¹Óãº
sudo ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2
¿ÉÒÔÐÞÕýÕâ¸öBUG
ͨ¹ýеÃÁ¢°²×°phpµÄmemcachedÄ£¿é£¬×¢Ïú/etc/php5/conf.d/memcached.iniÀïÃæµÄ¡°;¡±£¬ÖØÆôapache£¬µ÷ÓÃphpinfo()³öÏÖmemcachedµÄÐÅÏ¢
Ö´ÐУº
/usr/local/bin/memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
memcachedµÄ·þÎñÕýʽÆô¶¯
Memcache::add ¡ª Ìí¼ÓÒ»¸öÖµ£¬Èç¹ûÒѾ´æÔÚ£¬Ôò·µ»Øfalse
Memcache::addServer ¡ª Ìí¼ÓÒ»¸ö¿É¹©Ê¹ÓõķþÎñÆ÷µØÖ·
Memcache::close ¡ª ¹Ø±ÕÒ»¸öMemcache¶ÔÏó
Memcache::connect ¡ª ´´½¨Ò»¸öMemcache¶ÔÏó
memcache_debug ¡ª ¿ØÖƵ÷ÊÔ¹¦ÄÜ
Memcache::decrement ¡ª ¶Ô±£´æµÄij¸ökeyÖеÄÖµ½øÐмõ·¨²Ù×÷
Memcache::delete ¡ª ɾ³ýÒ»¸ökeyÖµ
Memcache::flush ¡ª Çå³ýËùÓлº´æµÄÊý¾Ý
Memcache::get ¡ª »ñÈ¡Ò»¸ökeyÖµ
Memcache::getExtendedStats ¡ª »ñÈ¡½ø³Ì³ØÖÐËùÓнø³ÌµÄÔËÐÐϵͳͳ¼Æ
Memcache::getServerStatus ¡ª »ñÈ¡ÔËÐзþÎñÆ÷µÄ²ÎÊý
Memcache::getStats ¡ª ·µ»Ø·þÎñÆ÷µÄһЩÔËÐÐͳ¼ÆÐÅÏ¢
Memcache::getVersion ¡ª ·µ»ØÔËÐеÄMemcacheµÄ°æ±¾ÐÅÏ¢
Memcache::increment ¡ª ¶Ô±£´æµÄij¸ökeyÖеÄÖµ½øÐмӷ¨²Ù×÷
Memcache::pconnect ¡ª ´´½¨Ò»¸öMemcacheµÄ³Ö¾ÃÁ¬½Ó¶ÔÏó
Memcache::replace ¡ª R¶ÔÒ»¸öÒÑÓеÄkey½øÐи²Ð´²Ù×÷
Memcache::set ¡ª Ìí¼ÓÒ»¸öÖµ£¬Èç¹ûÒѾ´æÔÚ£¬Ôò¸²Ð´
Memcache::setCompressThreshold ¡ª ¶Ô´óÓÚijһ´óСµÄÊý¾Ý½øÐÐѹËõ
Memcache::setServerParams ¡ª ÔÚÔËÐÐʱÐ޸ķþÎñÆ÷µÄ²ÎÊý
½¨ÒéÓÃÃæÏò¶ÔÏóµÄ·½Ê½À´²âÊÔÕâ¸ö¿â£º
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $version = $memcache->getVersion(); echo "Server's version: ".$version." \n"; ?>Memcache::getVersion·½·¨µÄ×÷ÓÃÊÇ·µ»ØÔËÐеÄMemcacheµÄ°æ±¾ÐÅÏ¢¡£
Memcache::getStats ·½·¨µÄ×÷ÓÃÊÇ·µ»Ø·þÎñÆ÷µÄһЩÔËÐÐͳ¼ÆÐÅÏ¢¡£Memcache::getStats·½·¨ÓÐÈý¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊý±íʾҪÇ󷵻صÄÀàÐÍ£ºreset, malloc, maps, cachedump, slabs, items, sizes;µÚ¶þ¸ö²ÎÊýºÍµÚÈý¸ö²ÎÊýÊÇÔÚµÚÒ»¸ö²ÎÊýÉèÖÃΪ¡°cachedump¡±Ê±Ê¹Óõġ£Memcache::getExtendedStats·½·¨µÄ ×÷ÓÃÊÇ»ñÈ¡½ø³Ì³ØÖÐËùÓнø³ÌµÄÔËÐÐϵͳͳ¼Æ¡£
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); print_r($memcache->getStats()); /** * Array * ( * [pid] => 8052 * [uptime] => 9205 * [time] => 1205898428 * [version] => 1.2.5 * [pointer_size] => 32 * [rusage_user] => 0.008000 * [rusage_system] => 0.000000 * [curr_items] => 1 * [total_items] => 17 * [bytes] => 57 * [curr_connections] => 2 * [total_connections] => 15 * [connection_structures] => 3 * [cmd_get] => 9 * [cmd_set] => 23 * [get_hits] => 5 * [get_misses] => 4 * [evictions] => 0 * [bytes_read] => 671 * [bytes_written] => 850 * [limit_maxbytes] => 10485760 * [threads] => 1 * ) */ ?>Memcache::connect·½·¨µÄ×÷ÓÃÊÇ´´½¨Ò»¸öMemcache¶ÔÏó¡£Memcache::pconnect·½·¨µÄ×÷ÓÃÊÇ´´½¨Ò»¸öMemcacheµÄ³Ö¾ÃÁ¬½Ó¶ÔÏó¡£Memcache::close·½·¨µÄ×÷ÓÃÊǹرÕÒ»¸öMemcache¶ÔÏó¡£
Memcache::set ·½·¨µÄ×÷ÓÃÊÇÌí¼ÓÒ»¸öÖµ£¬Memcache::set·½·¨ÓÐËĸö²ÎÊý£¬µÚÒ»¸ö²ÎÊýÊÇkey£¬µÚ¶þ¸ö²ÎÊýÊÇvalue£¬µÚÈý¸ö²ÎÊý¿ÉÑ¡£¬±íʾÊÇ·ñѹËõ±£´æ£¬ µÚËĸö²ÎÊý¿ÉÑ¡£¬ÓÃÀ´ÉèÖÃÒ»¸ö¹ýÆÚ×Ô¶¯Ïú»ÙµÄʱ¼ä¡£Memcache::add·½·¨µÄ×÷ÓúÍMemcache::set·½·¨ÀàËÆ£¬Çø±ðÊÇÈç¹û Memcache::add·½·¨µÄ·µ»ØֵΪfalse£¬±íʾÕâ¸ökeyÒѾ´æÔÚ£¬¶øMemcache::set·½·¨Ôò»áÖ±½Ó¸²Ð´¡£ Memcache::get·½·¨µÄ×÷ÓÃÊÇ»ñÈ¡Ò»¸ökeyÖµ£¬Memcache::get·½·¨ÓÐÒ»¸ö²ÎÊý£¬±íʾkey¡£Memcache::replace ·½·¨µÄ×÷ÓÃÊǶÔÒ»¸öÒÑÓеÄkey½øÐи²Ð´²Ù×÷£¬Memcache::replace·½·¨ÓÐËĸö²ÎÊý£¬×÷ÓúÍMemcache::set·½·¨µÄÏàͬ¡£ Memcache::delete·½·¨µÄ×÷ÓÃÊÇɾ³ýÒ»¸ökeyÖµ£¬Memcache::delete·½·¨ÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊý±íʾkey£¬µÚ¶þ¸ö²ÎÊý¿É Ñ¡£¬±íʾɾ³ýÑÓ³ÙµÄʱ¼ä¡£
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->set( 'name', 'leo', 0, 30); if(!$memcache->add( 'name', 'susan', 0, 30)) { echo 'susan is exist'; }; $memcache->replace( 'name', 'lion', 0, 300); echo $memcache->get( 'name'); $memcache->delete( 'name', 5); ?>memcache_debug()º¯ÊýµÄ×÷ÓÃÊÇ¿ØÖƵ÷ÊÔ¹¦ÄÜ£¬Ç°ÌáÊÇphpÔÚ±àÒëµÄʱºòʹÓÃÁ˨Cenable-debugÑ¡Ï·ñÔòÕâ¸öº¯Êý²»»áÓÐ×÷Óá£
Memcache::addServer ·½·¨µÄ×÷ÓÃÊÇÌí¼ÓÒ»¸ö¿É¹©Ê¹ÓõķþÎñÆ÷µØÖ·£¬Memcache::addServer·½·¨ÓÐ8¸ö²ÎÊý£¬³ýÁ˵ÚÒ»¸ö²ÎÊýÒâÍ⣬ÆäËû¶¼ÊÇ¿ÉÑ¡µÄ£¬µÚÒ»¸ö²ÎÊý±í ʾ·þÎñÆ÷µÄµØÖ·£¬µÚ¶þ¸ö²ÎÊý±íʾ¶Ë¿Ú£¬µÚÈý¸ö²ÎÊý±íʾÊÇ·ñÊÇÒ»¸ö³Ö¾ÃÁ¬½Ó£¬µÚËĸö²ÎÊý±íʾÕą̂·þÎñÆ÷ÔÚËùÓзþÎñÆ÷ÖÐËùÕ¼µÄȨÖØ£¬µÚÎå¸ö²ÎÊý±íʾÁ¬½ÓµÄ³ÖÐø ʱ¼ä£¬µÚÁù¸ö²ÎÊý±íʾÁ¬½ÓÖØÊԵļä¸ôʱ¼ä£¬Ä¬ÈÏΪ15,ÉèÖÃΪ-1±íʾ²»½øÐÐÖØÊÔ£¬µÚÆ߸ö²ÎÊýÓÃÀ´¿ØÖÆ·þÎñÆ÷µÄÔÚÏß״̬£¬µÚ8¸ö²ÎÊýÔÊÐíÉèÖÃÒ»¸ö»Øµôº¯Êý À´´¦Àí´íÎóÐÅÏ¢¡£
Memcache::setServerParams·½·¨µÄ×÷ÓÃÊÇÔÚÔËÐÐʱÐ޸ķþÎñÆ÷µÄ²ÎÊý£¬Memcache::setServerParams·½·¨ÓÐ Áù¸ö²ÎÊý£¬Memcache::addServer·½·¨ÉÙÁ˵ÚÈýºÍµÚËĸö²ÎÊý¡£ Memcache::getServerStatus·½·¨µÄ×÷ÓÃÊÇ»ñÈ¡ÔËÐзþÎñÆ÷µÄ²ÎÊý£¬Á½¸ö²ÎÊý·Ö±ð±íʾµÄµØÖ·ºÍ¶Ë¿Ú¡£
<?php function _callback_memcache_failure($host, $port) { print "memcache '$host:$port' failed"; } $memcache = new Memcache; $memcache->addServer('192.168.1.116', 11211); $memcache->setServerParams('192.168.1.116', 11211, 1, 15, true, '_callback_memcache_failure'); echo $memcache->getServerStatus('192.168.1.116', 11211); ?>Memcache::flush·½·¨µÄ×÷ÓÃÊÇÇå³ýËùÓлº´æµÄÊý¾Ý£¬µ«ÊDz»»áÏ÷ȥʹÓõÄÄÚ´æ¿Õ¼ä¡£
Memcache::increment·½·¨µÄ×÷ÓÃÊǶԱ£´æµÄij¸ökeyÖеÄÖµ½øÐмӷ¨²Ù×÷£¬Memcache::decremen·½·¨µÄ×÷ÓÃÊǶԱ£´æµÄij¸ökeyÖеÄÖµ½øÐмõ·¨²Ù×÷¡£
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211); $memcache->set('test_item', 8); $memcache->increment('test_item', 4); echo $memcache->decrement('test_item', 7); // ÏÔʾ 5 ?>setCompressThreshold·½·¨µÄ×÷ÓÃÊǶԴóÓÚijһ´óСµÄÊý¾Ý½øÐÐѹËõ¡£setCompressThreshold·½·¨ÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊý±íʾ´¦ÀíÊý¾Ý´óСµÄÁÙ½çµã£¬µÚ¶þ¸ö²ÎÊý±íʾѹËõµÄ±ÈÀý£¬Ä¬ÈÏΪ0.2¡£
<?php $memcache = new Memcache; $memcache->addServer('memcache_host', 11211); $memcache->setCompressThreshold(20000, 0.2); ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ