首页 > mysql > memcached +mysql+php 测试例子

memcached +mysql+php 测试例子

2010年5月18日 eric 发表评论 阅读评论

最近看了看memcached 缓存 mysql,经过一段时间的研究·把自己测试方法写出来,给像我一样的初学者用~
我的环境是 nginx + php-fpm + apc + mysql

编译安装memcached

tar zxvf memcached-1.4.0.tar.gz
cd memcached-1.4.0
./configure --prefix=/usr
make
make install

启动memcached

memcached -d -m 64 -u root -l 192.168.6.191 -p 11211 -c 64 -P /tmp/memcached.pid
/usr/local/mysql/bin/mysql -uroot -p

创建一个测试数据库 mydb

create database mydb;

创建一个空的数据表 personal_info

CREATE TABLE `personal_info` (
`pi_id` bigint(20) NOT NULL auto_increment,
`pi_name` varchar(50) NOT NULL,
`pi_tel` varchar(15) default NULL,
`pi_qq` varchar(15) default NULL,
`pi_email` varchar(50) default NULL,
PRIMARY KEY (`pi_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

给表插入数据

INSERT INTO `mydb`.`personal_info` (
`pi_id` ,
`pi_name` ,
`pi_tel` ,
`pi_qq` ,
`pi_email`
)
VALUES (
'1', 'eric', '13611031222', '55555555', 'eric@nginxs.com'
);

创建一个 php 文件 mysql-memcache.php

<?php
$memcachehost = '192.168.6.191';
$memcacheport = 11211;
$memcachelife = 60;
$memcache = new Memcache;
$memcache->connect($memcachehost,$memcacheport) or die ("Could not connect");
$query="select * from personal_info limit 10";
$key=md5($query);
if(!$memcache->get($key))
{
        $conn=mysql_connect("localhost","root","passwd");
        mysql_select_db(mydb);
        $result=mysql_query($query);
        while ($row=mysql_fetch_assoc($result))
        {
            $arr[]=$row;
        }
        $f = 'mysql';
        $memcache->add($key,serialize($arr),0,30);    //mysql 查询后,插入 memcached
        $data = $arr ;
}
else{
    $f = 'memcache';
    $data_mem=$memcache->get($key);
    $data = unserialize($data_mem);
}
echo $f;
echo "<br>";
//print_r($data);
foreach($data as $a)
{
        echo "number is <b><font color=#FF0000>$a[pi_id]</font></b>";
        echo "<br>";
        echo "name is <b><font color=#FF0000>$a[pi_name]</font></b>";
        echo "<br>";
        echo "tel is <b><font color=#FF0000>$a[pi_tel]</font></b>";
        echo "<br>";
        echo "qq is <b><font color=#FF0000>$a[pi_qq]</font></b>";
        echo "<br>";
        echo "email is <b><font color=#FF0000>$a[pi_email]</font></b>";
        echo "<br>";

}
?>

测试 第一次访问 提示 mysql

刷新,第二次访问,提示memcache

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/152.html

分类: mysql 标签: , ,
  1. 2018年4月6日06:20 | #1

    If possible, please, like! Might individual allow me to using Eric’s linux and nginx!
    > memcached +mysql+php 测试例子 course of action??
    All of our professor enrolled granted a pursuit to write down 2000 letters onto it.
    Even So I do not know anything! Assist!

  2. 2018年4月7日12:29 | #2

    Good day! Do you use Twitter? I’d like to follow you if that would be ok.
    I’m definitely enjoying your blog and look forward to new updates.

  3. 2018年4月8日05:40 | #3

    These are truly impressive ideas in regarding blogging.
    You have touched some nice factors here. Any way keep up wrinting.

  4. 2018年4月8日15:55 | #4

    This web site is superb! I am delighted that I’ve located it.
    All content articles are appealing and well penned. As for me, I don’t
    much like writing and it doesn’t provide any
    enjoyment or other sorts of good feelings to me.
    But I must do this or I’ll fail my studying.

    Even so, I’ve found a solution to this issue. On this website online paper writing service
    reviews you can find a lot of evaluations of penning companies
    and select the most respected one.

  5. 2018年4月9日00:22 | #5

    I’ve never thought about %BT% in this way. Thank you very much author, it was very interesting to read!
    This is a wonderful illustration of great authoring for those who can’t
    write very well. Many individuals have this kind of problem.
    On the other hand, I’ve located an answer to this problem.
    On this web page best custom writing reviews you will find a lot of ratings of authoring firms and opt for the most
    reputable one.

  6. 2018年4月9日10:01 | #6

    Excelente Web site , Furar a o bom trabalho.
    Obrigado pelo seu tempo ! http://www.kameli.net/marq/?p=2570

  7. 2018年4月9日11:18 | #7

    I’ve never thought of %BT% like this. Many thanks author, it was very interesting to read!
    You definitely possess a skills! I would like to be as good at
    composing as you, but it’s not my cup of tea. I don’t know whether I possibly could take care
    of this trouble without this blog Windy. The crew of the internet site produces wonderful evaluations of different essays penning organizations in order to help people keep away from fraud and find top
    websites.

  8. 2018年4月9日21:43 | #8

    Truly no matter if someone doesn’t understand afterward
    its up to other people that they will help, so
    here it takes place. http://www.femens.gr/UserProfile/tabid/43/UserID/887021/Default.aspx

  9. 2018年4月10日00:53 | #9

    Hi, yes this piece of writing is genuinely good and I have learned lot of things from it about blogging.
    thanks. http://www.ya.lt/user/FranciscoPenny3/

  10. 2018年4月10日05:18 | #10

    Wonderful beat ! I would like to apprentice while you
    amend your website, how could i subscribe for a blog site?
    The account aided me a acceptable deal. I had been tiny bit acquainted of
    this your broadcast provided bright clear concept http://griffithzone.com/UserProfile/tabid/61/userId/22372263/Default.aspx

  11. 2018年4月11日00:05 | #13

    Fantastic blog site and fantastic post! It is clear that the
    publisher is experienced and has a huge practical knowledge in posting.

    You certainly have a talent! I wish to be as good at composing as you,
    but it’s not my cup of tea. Taking into consideration this, I couldn’t
    envision how can I manage the trouble without this web
    page assignment writing service review. In-depth overviews
    of the most famous paper penning organizations can guide every visitor to select a suitable firm.

  12. 2018年4月11日10:05 | #14

    If some onne desires to be updated with latest technologies after that
    he must bee go to see this site and be up to date alll the time.

    Read online or download your favorite books

    TÉLÉCHARGER LE PDF EPUB MOBI https://kaarinan.ml/sitemaps.xml

  13. 2018年4月11日23:12 | #15

    Hey! Wonderful article! I love the way you described %BT%.
    Could you create some tutorial or tips and hints for those people who would like to increase
    personal composing skills? It may be super useful, specifically for learners,
    due to the fact modern day students must write a big
    amount of numerous paperwork for college and universities.
    There is however ways to resolve this trouble. If you click this link Fredericka
    you will find a website with in-depth assessments of web based essay writing services.

    You can select the one which is the best for you and get a
    essay you need.

  14. 2018年4月13日06:40 | #16

    My mom has actually been wanting to know our family to help her consisting of Eric’s linux
    and nginx! > memcached +mysql+php 测试例子. I`ve stashed exclaiming I will don’t have the time and definately will make during the entire end of the week.
    Nevertheless veracity – I’ve got little idea what! May easily the person move the post with this complete,
    please be sure to?

  15. 2018年4月13日13:18 | #17

    Use a buffer with a red pad to remove excess oil.

  16. 2018年4月14日08:49 | #18

    When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each
    time a comment is added I get several e-mails with the same comment.
    Is there any way you can remove me from that service?

    Bless you!

  17. 2018年4月15日06:11 | #19

    Mould spores will not survive in dry climates.

  18. 2018年4月16日00:46 | #20

    Cleans and prepares ground for high polish.

  19. 2018年4月16日12:29 | #21

    We didn’t discover outcomes for: hardwood flooring.

  20. 2018年4月16日23:22 | #23

    Remodeling a finished basement is costlier.

  21. 2018年4月17日23:56 | #24

    Polished concrete floors have few disadvantages.

  22. 2018年4月20日18:46 | #25

    Polished concrete flooring have few disadvantages.

  23. 2018年4月21日00:26 | #26

    Good day I am so happy I found your blog page, I really found you by mistake, while I
    was browsing on Aol for something else, Regardless I am here now and would just like to say thank you for
    a incredible post and a all round exciting blog (I also love the theme/design), I don’t have
    time to go through it all at the minute but I have bookmarked it and also added your RSS
    feeds, so when I have time I will be back to read much more, Please do keep up the superb jo. http://spartancxdev.com/%d0%ba%d0%b0%d0%ba-%d0%b2%d0%b7%d1%8f%d1%82%d1%8c-%d1%80%d0%b0%d0%b7%d0%bd%d0%be%d1%80%d0%b0%d0%b1%d0%be%d1%87%d0%b5%d0%b3%d0%be-%d0%bd%d0%b0-%d1%81%d1%82%d1%80%d0%be%d0%b9%d0%ba%d1%83/

  24. 2018年4月21日16:18 | #27

    Very nice article, totally what I wanted to find. http://addressbookie.com/groups/how-to-hire-an-essay-writer-online/

  25. 2018年4月22日01:00 | #28

    Hi tһere would you mind letting me know whіch webh᧐st you’re
    using? I’ve loaded yⲟur blog in 3 completely different browsers and
    I muѕt saʏ this blog loads a lot faster then most. Can you suggest a goоⅾ internet
    hosting prⲟvider at a reasonable priсe? Thankos a lot, I appreciate it!

  26. 2018年4月22日05:06 | #29

    Ebook a talented lawn pro in Kansas Metropolis.

  27. 2018年4月24日03:15 | #30

    Save on basement restore products with SANI-TRED!

订阅评论
4+4= (必填)