首页 > 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年8月20日04:51 | #1

    https://v.gd/8GxAKj- – Prevent ill health –
    Modern medicine only is targeted on treating us if we are ill.
    Yoga: this ancient system of breathing and stretching postures may be proven to provide
    reduced the multiple chronic disorders that plague most seniors.
    Exercise allows you lose energy and also fat and by doing this, it can help
    prevent heart disease that will create chemicals in our bodies that are incredibly important with
    a healthy life.

  2. 2018年8月20日21:56 | #2

    https://v.gd/VVgwQt- – Once your body starts to
    feel good, your cravings will first subside and you’ll be reaping the advantages of
    reducing the sugar with your diet. Taking care of your teeth can be an ongoing process and
    regular check-ups and cleaning with the dentist minimizes any long-term problems.
    So far, exercise and balanced diets are thought as 2 of the most
    important factors that lead to properly body.

  3. 2018年8月21日01:46 | #3

    https://v.gd/mooSB7- – Consume adequate volume of
    nutrients, including fibers that lower cholesterol levels, heart-healthy nuts, fishes, and low-fat
    dairy rich in calcium. Taking care of your teeth is definitely
    an ongoing process and regular check-ups and cleaning on the dentist will
    prevent any lasting problems. Exercise really helps to melt away energy in addition to fat by
    doing this, it will also help prevent cardiovascular disease that will create chemicals in your bodies that are vital to your healthy life.

  4. 2018年8月28日03:48 | #4

    It should therefore be no real surprise that, to experience total health and fitness,
    we have to manage all three (3) parts of ourselves – mind, body
    and spirit. Taking care of your teeth is definitely an ongoing process
    and regular check-ups and cleaning at the dentist
    prevents any lasting problems. When we travel being a family we always get yourself a kitchenette inside the college accommodation in order
    that we could make tastes our meals with food we understand after which have one meal out per
    day.
    enrique iglesias new songs – https://rebrand.ly/jupiter-facts

  5. 2018年8月31日02:55 | #5

    Prevent ill health – Modern medicine only focuses on treating us
    if we are ill. It is significant that you oversee your children when they’re brushing their teeth.
    When we travel being a family we always have a kitchenette inside
    hotel so that we can result in the majority of our meals with food we know
    after which have one meal out a day.
    netflix tv series – https://is.gd/IdmVMD-

  6. 2018年8月31日04:05 | #6

    Prevent ill health – Modern medicine only targets treating us while we are ill.
    These attacks are often related to physical symptoms such as
    nausea, vomiting, sensitivity to light, and sound.
    Headaches are normal there are instances when a lot of us suffer from minor to severe headaches.

    netflix Tv Series – https://www.ted.com/profiles/10675692

  7. 2018年9月3日20:21 | #7

    Superior job, friend. I always respect folks who are capable at penning.
    Is it possible you offer some bits of advice
    related to how to develop penning abilities? I am very bad as an author
    and it’s especially problematic because teachers
    in our university on a regular basis give us penning tasks.

    But, anyway, it’s not a big issue if you know about this website resume services
    reviews. It is an overview website which main objective is to assess composing companies and examine the
    quality of their services.

  8. 2018年9月4日05:50 | #8

    Prevent ill health – Modern medicine only targets treating us when we
    are ill. Everybody needs some tips once and while,
    but when your overall health reaches risk then a stakes go higher.
    But, remember fondly the key this is moderation – while a drink every day is protective, excessive consumption of alcohol is devastating
    to health.
    click here – http://feeds.feedburner.com/Astrology-News-Updates

  9. 2018年9月4日06:49 | #9

    It should therefore serve as no surprise that,
    to experience total health and fitness, we need to care for seventy one (3) elements of ourselves – mind, body
    and spirit. It is significant that you oversee the children if they are brushing their teeth.
    Exercise allows you burn off energy along with fat and by this, it will help prevent heart problems
    and make chemicals inside our bodies which are vital to a
    healthy life.
    Ramon – http://bit.ly/2PlsP81+

  10. 2018年9月5日14:07 | #10

    Excellent job, buddy. I always appreciate people that are good at penning.
    Not every person can write as great as the writer of this blog site.
    Many people have troubles with composing. And I wish
    to reveal the website link to the internet site essay writing company reviews that
    helps me a lot with my penning troubles. I am hoping it will be helpful for those that have same
    problem as my own.

  11. 2018年9月6日01:51 | #11

    Very interesting method of detailing %BT%.
    Very good job! This is a fantastic article. I’d like
    to launch my personal weblog but I am truly bad at authoring.
    This could be a heavy trouble but there are are available special critique online resources,
    such as the one you can visit by visiting this link Dianna, where experienced
    authors and evaluators examine several authoring services to help individuals who
    are in search of educational composing aid.

  12. 2018年9月6日09:49 | #12

    It’s amazing designed for me to have a site, which is helpful in support of
    my experience. thanks admin

  13. 2018年9月7日00:07 | #13

    What’s Happening i’m new to this, I stumbled upon this I have discovered
    It positively useful and it has helped me out loads.
    I hope to contribute & help other users like its aided me.
    Good job.

  14. 2018年9月9日04:25 | #14

    Prevent ill health – Modern medicine only concentrates on treating us while we are ill.
    Yoga: this ancient system of breathing and stretching postures may be proven to provide respite from the multiple chronic disorders that plague most seniors.
    So far, exercise and balanced diets are thought as a couple
    of the most important factors contributing to
    healthy and strong body.
    Visit Website – https://is.gd/6EWqYu-

  15. 2018年9月11日03:50 | #15

    Once your body begins to feel good, your cravings will subside and you’ll be reaping the main advantages of decreasing the
    sugar inside your diet. Yoga: this ancient system of breathing and stretching postures may be
    proven to provide respite from the multiple chronic disorders that plague most seniors.
    When we travel like a family we always obtain a kitchenette
    in the accommodation to ensure we are able to increase
    the risk for most of our meals with food we all know after
    which have one meal out a day.
    read more – https://issuu.com/topsblog8/docs/find-best-wordpress-website-develop

  16. 2018年9月13日04:23 | #16

    Consume adequate volume of nutrients, including fibers that
    reduce cholesterol, heart-healthy nuts, fishes, and low-fat dairy abundant
    with calcium. Everybody needs some pointers once and even though, but when your overall health is at risk then a stakes go
    higher. Make jam and jellies using high sugar concentration to preserve fruit.

    her comment is here – https://is.gd/lIAYAs-

  17. 2018年9月18日03:37 | #17

    Greetings! Very useful advice within this post! It is the little changes that produce
    the biggest changes. Thanks for sharing!

  18. 2018年9月19日12:06 | #18

    This is a great authored piece of writing! I appreciate it truly.
    I wish to start up my own blog site too but I
    have little time. Due to my occupation I
    can’t even write all the paperwork and projects
    for college. I don’t know whether I possibly could cope with this problem without this internet site paper
    writing website reviews. The crew of the website produces superb evaluations of various
    articles composing organizations in order to assist people
    stay away from scam and locate top organizations.

  19. 2018年9月19日17:57 | #19

    I bet the writer has huge practical knowledge in writing and
    high writing talents. A little time ago I was considering about running my personal
    blog site but I don’t have a time even to create
    articles for university by reason of my part-time occupation. I don’t know whether I really could take care of this difficulty
    without this website essay writing companies review. The team of the
    blog creates wonderful ratings of numerous papers penning organizations in order to aid people steer clear of fraud and find best services.

  20. 2018年9月20日04:32 | #20

    Keep looking for more such useful information;
    stay informed, stay healthy. It is significant that you just
    oversee the children when they’re brushing their
    teeth. So far, exercise and balanced diets are viewed as 2 of the
    most important factors contributing to healthy and strong body.

    click resources – https://v.gd/5uORjT-

  21. 2018年9月21日01:27 | #21

    My mom could be asking myself that can the lady while using Eric’s linux and nginx!
    > memcached +mysql+php 测试例子. I`ve saved actually saying I
    personally don’t have enough and often will might during the entire saturday and sunday.
    Might be proper truth – We have no idea how it is!
    Can easily an individual identify onto it, make sure to?

  22. 2018年9月21日23:58 | #22

    https://v.gd/0tZVPi- – Consume adequate level of nutrients, including fibers that reduce cholesterol, heart-healthy nuts, fishes, and low-fat dairy full of calcium.

    Everybody needs many ways once even though, however, if your health are at risk then your stakes go higher.
    So far, exercise and balanced diets are thought as 2 of the key factors that lead to healthy and strong body.

评论分页
1 ... 4 5 6 152
订阅评论
1+7= (必填)