×ðÁú¿­Ê±

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃMemcached¾ÙÐлº´æ²Ù×÷£¿

Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬»º´æ¹ØÓÚÍøÕ¾»òÕßÓ¦ÓóÌÐòµÄÐÔÄÜÓÅ»¯Ô½À´Ô½Ö÷Òª¡£ÔÚthinkphp6¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃmemcachedÀ´¾ÙÐлº´æ²Ù×÷£¬ÒÔÌá¸ßÓ¦ÓóÌÐòµÄÏìÓ¦ËÙÂÊ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp6¿ò¼ÜÖÐʹÓÃmemcached¾ÙÐлº´æ²Ù×÷¡£

Ò»¡¢Ê²Ã´ÊÇMemcached£¿

Memcached ÊǸßÐÔÄܵÄÂþÑÜʽÄڴ湤¾ß»º´æϵͳ£¬ÓÃÓÚ¼ÓËÙ¶¯Ì¬ Web Ó¦ÓóÌÐò¡£Ëüͨ¹ýÔÚ RAM Öд洢ÊéÇ©À´ïÔ̭ƵÈÔµÄÊý¾Ý¿â»á¼û£¬´Ó¶øÌá¸ß Web Ó¦ÓóÌÐòµÄÐÔÄÜ¡£ËüÒ²¿ÉÒÔÓÃÓÚ»º´æÆäËûͨË×ÄÚÈÝ£¬Èç HTML Ò³ÃæºÍ API ÏìÓ¦¡£

¶þ¡¢ÔõÑù×°ÖÃMemcached£¿

Ê×ÏÈ£¬ÐèÒªÔÚЧÀÍÆ÷ÉÏ×°ÖÃMemcached²Å»ªÊ¹Óá£ÔÚLinuxÏ£¬¿ÉÒÔʹÓÃapt-get¡¢yumµÈÏÂÁî×°Öá£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÏêϸҪÁìÈçÏ£º

1.×°Öù¤¾ß

sudo apt-get install build-essential

sudo apt-get install libevent-dev

2.ÏÂÔØMemcached

wget http://www.memcached.org/files/memcached-1.5.20.tar.gz

3.½âѹ²¢½øÈëÎļþ¼Ð

tar -zxvf memcached-1.5.20.tar.gz

cd memcached-1.5.20

4.±àÒëºÍ×°ÖÃ

./configure

make && make install

5.×°ÖÃPHPµÄMemcachedÀ©Õ¹

sudo apt-get install php-memcached

Èý¡¢ÔõÑùÔÚThinkPHP6ÖÐʹÓÃMemcached¾ÙÐлº´æ²Ù×÷£¿

1¡¢ÔÚconfig/cache.phpÖоÙÐÐÉèÖÃ

ÔÚconfig/cache.phpÎļþÖУ¬ÎÒÃÇÐèÒªÉèÖûº´æÇý¶¯Îªmemcached£¬ÒÔ¼°ÉèÖÃmemcachedµÄÏà¹ØÐÅÏ¢¡£

ÉèÖÃÈçÏ£º

<?php

return [
    // ĬÈÏ»º´æÇý¶¯
    'default' => env('cache.driver', 'memcached'),
    // »º´æÅþÁ¬·½·¨ÉèÖÃ
    'stores'  => [
        'file' => [
            'driver' => 'file',
            'path'   => runtime_path('cache'),
        ],
        'redis' => [
            'driver' => 'redis',
            'host'   => env('cache.redis.host', '127.0.0.1'),
            'port'   => env('cache.redis.port', 6379),
            'password' => env('cache.redis.password', ''),
            'select' => env('cache.redis.select', 0),
            'timeout' => env('cache.timeout', 0),
            'expire' => env('cache.expire', 0),
            'persistent' => false,
            'prefix' => '',
        ],
        'memcached' => [
            'driver'    => 'memcached',
            'host'      => env('cache.memcached.host', '127.0.0.1'),
            'port'      => env('cache.memcached.port', 11211),
            'username'  => env('cache.memcached.username', ''),
            'password'  => env('cache.memcached.password', ''),
        ],
    ],
];

µÇ¼ºó¸´ÖÆ

ÈçÉÏÉèÖÃÖУ¬ÐèҪעÖصÄÓУº

(1) »º´æÇý¶¯Ä¬ÒÔΪmemcached£º

´Ë´¦½«Ä¬ÈϵĻº´æÇý¶¯ÉèÖÃΪmemcached£¬Òâζ×ÅËùÓлº´æ²Ù×÷¶¼»áʹÓøÃÇý¶¯¡£

(2) storesÊý×éÖÐÔöÌímemcachedÑ¡Ï

ÔÚstoresÊý×éÖÐÔöÌíÁËmemcachedÑ¡Ï²¢ÉèÖÃÏà¹Ø²ÎÊýÓÃÓÚÅþÁ¬memcached¡£

2¡¢Ê¹Óûº´æ

ÔÚThinkPHP6¿ò¼ÜÖУ¬¿ÉÒÔʹÓûº´æÀàÀ´¾ÙÐлº´æ²Ù×÷¡£ÆäÖУ¬»º´æÀàÌṩÁËÖîÈçget¡¢set¡¢has¡¢deleteµÈÒªÁìÀ´ÖÎÀí»º´æ¡£

ʹÓÃÈçÏ´úÂ룺

<?php 

namespace appindexcontroller; 

use thinkacadeCache; 

class Index { 

    public function index() { 
        //дÈ뻺´æ 
        Cache::set('name', 'ThinkPHP6'); 

        //»ñÈ¡»º´æ 
        $name = Cache::get('name'); 

        //Åжϻº´æ 
        if ( Cache::has('name') ) { 
            //ɾ³ýÀÖ³É 
            Cache::delete('name'); 
        } 

        //Çå¿Õ»º´æ 
        Cache::clear(); 
    } 
}

µÇ¼ºó¸´ÖÆ

ËÄ¡¢½áÂÛ

ͨ¹ýÒÔÉÏËĸö°ì·¨£¬¾Í¿ÉÒÔÔÚThinkPHP6ÖÐʹÓÃMemcached¾ÙÐлº´æ²Ù×÷¡£Í¨¹ý»º´æÊÖÒÕ£¬¿ÉÒÔ´ó´óÌá¸ßÓ¦ÓóÌÐòµÄÏìÓ¦ËÙÂÊ£¬Ìá¸ßÓû§»á¼ûÌåÑé¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃMemcached¾ÙÐлº´æ²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿