php-在php中使用memcache

來源:互聯網
上載者:User

標籤:安裝路徑   查看   let   tps   string   dll   zip   array   沒有   

<?php  phpinfo();?>

查看電腦中的php是否已經安裝memcache擴充。

如果沒有:

(1)php的安裝路徑找到ext檔案夾

我的是 C:\wamp\bin\php\php5.5.12\ext

將下載的php_memcache.all檔案放進去

(2)在php.ini設定檔中,加

extension=php_memcache.dll

(3)重啟伺服器

我的出現了問題,參考的https://www.oschina.net/question/1254404_248665

用的php_memcache-3.0.8-5.5-ts-vc11-x86.zip

 

常用函數:

具體可以參考PHP手冊 “LXXXIV. Memcache Functions” 這章。
  Memcache物件導向的常用介面包括:
  Memcache::connect -- 開啟一個到Memcache的串連
  Memcache::pconnect -- 開啟一個到Memcache的長串連
  Memcache::close -- 關閉一個Memcache的串連
  Memcache::set -- 儲存資料到Memcache伺服器上
  Memcache::get -- 提取一個儲存在Memcache伺服器上的資料
  Memcache::replace -- 替換一個已經存在Memcache伺服器上的項目(功能類似Memcache::set)
  Memcache::delete -- 從Memcache伺服器上刪除一個儲存的項目
  Memcache::flush -- 重新整理所有Memcache伺服器上儲存的項目(類似於刪除所有的儲存的項目)
  Memcache::getStats -- 擷取當前Memcache伺服器啟動並執行狀態
  Memcache::addServer -- 分布式伺服器添加一個伺服器

 

<?php  $mem=new Memcache;  $mem->connect("localhost",11211);  $mem->add("mystr","this is a Memcache test!",MEMCACHE_COMPRESSED,3600);//  $mem->set("mystr","wwwwwwwwwwwwwwwwwww",MEMCACHE_COMPRESSED,3600);  $str=$mem->get("mystr");  echo "string:".$str."<br>";  $mem->add("myarr",array("aaa","bbb","cccc","dddd"));  print_r($mem->get("myarr"));  echo ‘<br>‘;  class Person{    var $name="zhangsan";    var $age=10;  }  $mem->add("myobj",new Person);  var_dump($mem->get("myobj"));  $mem->close();?>

  

在php什麼地方使用memcache

一、資料庫讀出來的資料(select)使用memcache處理

二、在會話控制session中使用

 

Memcache的安全(不讓別人訪問)

1、內網

2、設定防火牆

 

php-在php中使用memcache

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.