国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Memcached - PHP 安裝&使用
Memcached - PHP 安裝&使用
下載Memcached:
http://danga.com/memcached/download.bml
安裝:
下載安裝libevent,已安裝可跳過:
下載地址:http://www.monkey.org/~provos/libevent/
Memcached For PHP Module下載地址:
http://pecl.php.net/package/memcache
http://cn.php.net/manual/zh/ref.memcache.php
安裝Memcached服務(wù)端
root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install
安裝完畢重啟服務(wù):
root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root
安裝PHP模塊
root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install
安裝完后可能會有如下提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
修改php.ini
extension_dir = "./"
修改為:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
添加一行:
extension=memcache.so
安裝完畢,測試:
PHP代碼
<?php   $memcache = new Memcache; //創(chuàng)建一個memcache對象   $memcache->connect('localhost', 11211) or die ("Could not connect"); //連接Memcached服務(wù)器   $memcache->set('key', 'test'); //設(shè)置一個變量到內(nèi)存中,名稱是key 值是test   $get_value = $memcache->get('key'); //從內(nèi)存中取出key的值   echo $get_value;
Memcache的內(nèi)定Function
connect(ip, port)
set(key, value)  數(shù)據(jù)壓縮:set(key, value, MEMCACHE_COMPRESSED)
get(key)
increment, 同set(好像多了個計數(shù)功能,沒試過)
getStats() 返回當前內(nèi)存占用情況(return array) print_r($memcached->getStats());
flush  清空內(nèi)存占用.
代碼范例(來自chinaunix):
PHP代碼
<?php   //訪問統(tǒng)計   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");   if($s=$memcache->get(’a’)) {       $s=$s+1;       $memcache->set(’a’,$s);   }   else   $memcache->set(’a’,1);   echo ’訪問結(jié)果為:’.$s;   ?>
等效
PHP代碼
<?php   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");      if($s=$memcache->increment(’a’,1)) {       echo $s;       }   else   $memcache->set(’a’,1);   ?>
數(shù)據(jù)壓縮
PHP代碼
<?php   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");   $test=(str_repeat(’jetwong’,100000));   $memcache->set(’b’,($test));   ?>   使用壓縮:   <?php   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");   $test=(str_repeat(’jetwong’,100000));   $memcache->set(’b’,($test),MEMCACHE_COMPRESSED);   ?>
內(nèi)存的更新清理
PHP代碼
<?php   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");      /*設(shè)置值*/   $status = $memcache->getStats();   echo ’設(shè)置前內(nèi)存使用情況’.$status[’bytes’].’<br>’;   echo ’設(shè)置后’;   for($i=0;$i<9;$i++) {       $memcache->set(’b’.$i,rand(1,99));           echo ’<br>’.$i.’->’.$memcache->get(’b’.$i);          }      /*查看設(shè)置的值*/   $status = $memcache->getStats();   echo ’delete前內(nèi)存使用情況’.$status[’bytes’].’<br>’;   echo ’<br>開始delete’;   for($i=0;$i<9;$i++) {       $memcache->delete(’b’.$i);           echo ’<br>’.$i.’->’.$memcache->get(’b’.$i);   }      /*查看flush使用的情況*/   $status = $memcache->getStats();   echo ’使用flush前內(nèi)存使用情況’.$status[’bytes’].’<br>’;   echo ’使用flush情況:’;   for($i=0;$i<9;$i++) {       $memcache->set(’b’.$i,rand(1,99));           echo ’<br>’.$i.’->’.$memcache->get(’b’.$i);     }   $memcache->flush();   echo ’flush之后:’;   for($i=0;$i<9;$i++) {               echo ’<br>’.$i.’->’.$memcache->get(’b’.$i);   }   $status = $memcache->getStats();   echo ’flush后內(nèi)存使用情況’.$status[’bytes’].’<br>’;   ?>
內(nèi)存超量測試
PHP代碼
<?php   $memcache = new Memcache;   $memcache->connect(’localhost’, 11211) or die ("Could not connect");      //600K左右   $test1= str_repeat(’jetlee’,100000);   //600K左右   $test2= str_repeat(’jetlee’,100000);   //600K左右   $test3= str_repeat(’李連杰’,200000);   //600K左右   $test4= str_repeat(’連杰李’,100000);   //200K   $test5= file_get_contents(’http://img.pconline.com.cn/images/photoblog/2988177/20068/4/1154688770042_mthumb.JPG’);   $test6= file_get_contents(’http://img.pconline.com.cn/images/photoblog/1767557/20069/28/1159417108902_mthumb.jpg’);      for($i=1;$i<=6;$i++) {       $j=’test’.$i;       if($memcache->set($j,$$j)) {           echo $j.’->設(shè)置成功<br>’;           $status = $memcache->getStats();           echo ’內(nèi)存:’.$status[’bytes’].’<br>’;       }       else {           echo $j.’->設(shè)置失敗<br>’;       }   }   ?>
總結(jié) PHP代碼
<?   //設(shè)置篇   if($data = $memcache->get(’k’,$v)) {       //顯示我們的數(shù)據(jù)       }   else {       $data = get_from_database; //得到數(shù)據(jù)源       if(!$memcache->set(’k’,$data), MEMCACHE_COMPRESSED) //開始設(shè)置       log();    //不成功,記錄失敗信息       }   ?>
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Memcached安裝以及PHP的調(diào)用
php+mysql實現(xiàn)簡單的增刪改查功能
高等游民白烏鴉對《細說PHP》的筆記(10)
php session存儲到文件、memcache或redis
服務(wù)器的大用戶量的承載方案 Nginx Squid Apache PHP MySQL
memcache
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服