php使用memcache處理快取資料

來源:互聯網
上載者:User

標籤:io   os   使用   ar   資料   sp   代碼   on   c   

        一般來說,如果並發量不大的情況,使不使用緩衝技術並沒有什麼影響,但如果高並發的情況,使用緩衝技術就顯得很重要了,可以很好的減輕資料庫和伺服器的壓力,當然解決高並發的技術有很多,這裡只是以緩衝的角度來說明使用memcache的便捷性和方便性,緩衝技術中,與memcache類似的還有redis,這裡不做介紹!

        使用memcache的前提是需要在服務端先配置好memcahche的環境!確認memcahce可以正常串連之後就可以在程式使用了!

        具體代碼如下:

<?phpheader("content-type:text/html;charset:utf-8");include "../inc/str.php";include "../Inc/mysql.php";include "../Inc/const.php";if($is_memcache){    // $memcache操作    $memcache = new Memcache;    try{        [email protected]$memcache->connect($memcache_server, $memcache_port);             if($memc){            $getMsg=$memcache->get("360GetMsgDate");//擷取緩衝中的資料            // $memcache->delete("360GetMsgDate");            if(!$getMsg){                   $jsonDate = getMessage($f_serverName,$f_userName,$f_password,$f_htNewsDate);                $memcache->set("360GetMsgDate",$jsonDate,0,3600); //設定緩衝時間為一小時                echo $jsonDate;            }            else{                       echo $getMsg;            }                    $memcache->close();        }        else{            //code        }    }catch(Exception $e){        print $e->getMessage();    }    unset($memcache);    //結束$memcache操作}else{  echo  getMessage($f_serverName,$f_userName,$f_password,$f_htNewsDate);}

        

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.