Grasp.Today

memcached php-memcache 扩展

 1 1.安装 libevent   
 2 
 3     wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz   
 4     
 5     tar -zxvf libevent-2.0.21-stable.tar.gz  
 6     
 7     进入目录  
 8     ./configure --prefix=/usr/local/libevent   
 9     make  
10     make install 
11 
12 2.安装 memcached   
13 
14      wget -c http://memcached.org/files/memcached-1.5.7.tar.gz
15      
16      解压并进入目录  
17      ./configure --with-libevent=/usr/local/libevent  --prefix=/usr/local/memcached    
18      make  
19      make install  
20 
21 3.启动memcached 
22 
23     /usr/local/memcached/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211  
24     
25     ps -aux | grep memcached 
26 
27 4.开机启动    重启成效   
28 
29     vim /etc/rc.local  
30     /usr/local/memcached/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211
31 
32 5.安装  php memcache扩展  
33 
34     wget -c https://github.com/websupport-sk/pecl-memcache/archive/php7.zip
35      
36     unzip php7.zip 
37     
38     cd pecl-memcache-php7/   
39     
40     
41     /usr/local/php7/bin/phpize  
42     
43     ./configure --with-php-config=/usr/local/php7/bin/php-config   
44     
45     make 
46     make install  
47     
48      cd /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/   
49      发现 多了一个 memcache.so   不是 memcached.so   
50      
51      
52      vim /usr/local/php7/etc/php.ini 
53      
54      extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
55      
56      extension = memcache.so 
57      
58      service php-fpm restart  
59      
60      
61      /usr/local/php7/bin/php -m  查看  
62      
63      会出现一个 memcache 
64      
65      index.php
66       session_start();
67        if (!isset($_SESSION['TEST'])) {
68             $_SESSION['TEST'] = time();
69         }
70     
71         $_SESSION['TEST3'] = time();
72         $_SESSION['name'] = 'liwenkai';
73         print $_SESSION['TEST'];
74         print "<br><br>";
75         print $_SESSION['TEST3'];
76         print "<br><br>";
77         echo session_id();
78     
79     test.php
80     
81       session_start();
82       $mem = new Memcache();
83       $mem->addServer('127.0.0.1',11211);
84       var_dump($mem->get(session_id()));
85     
86     
87      
88   
89      
90      

 

posted @ 2018-04-26 17:57  gaohj  阅读(204)  评论(0编辑  收藏  举报