首页 > 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年6月6日16:37 | #1

    probiotics benefits gundry diet probiotics [url=https://probiotics.us.org]probiotics[/url]

  2. 2018年6月9日17:40 | #2

    NYC Personal Injury & Accident Law Firm
    You actually make it seem so easy with your presentation but I find this topic to be really something that I
    think I would never understand. It seems too complicated and very broad
    for me. I’m looking forward for your next post, I will try to get the hang of it!

  3. 2018年6月9日21:13 | #3

    http://bitly.com/2kWtsaW
    We absolutely love your blog and find almost all of your post’s to be just what
    I’m looking for. Would you offer guest writers to write content available
    for you? I wouldn’t mind writing a post or elaborating on a few of the subjects you write related to here.
    Again, awesome web log! read more

  4. 2018年6月10日05:39 | #4

    find out this here
    Hello there, I found your web site via Google at the same
    time as searching for a similar subject, your site came up,
    it seems to be great. I’ve bookmarked it in my google bookmarks.

    Hi there, just was alert to your blog via Google, and located that
    it’s truly informative. I am going to watch out for brussels.
    I’ll appreciate for those who proceed this in future.
    Numerous people shall be benefited from your writing.

    Cheers! https://v.gd/otcB28-

  5. 2018年6月10日06:09 | #5

    visit site
    I could not resist commenting. Very well written! https://v.gd/291c1W-

  6. 2018年6月11日04:43 | #6

    Hello there! This is kind of off topic but I need some guidance
    from an established blog. Is it tough to set up your own blog?
    I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to begin. Do you have
    any tips or suggestions? Thank you

  7. 2018年6月11日13:07 | #7

    bookmarked!!, I love your web site! https://home.dbiservices.com/athlete-essay-writer-hire

  8. 2018年6月13日17:31 | #8

    new york injury attorney
    Very rapidly this web page will be famous amid all blogging and site-building visitors, due
    to it’s good posts

  9. 2018年6月13日20:44 | #9

    psychics in nashua nh psychics near gilbert az psychic deceased pets
    can anyone recommend a good psychic in perth twin psychic twitter where can i get a real psychic reading psychic fishersville
    va psychic reading legal disclaimer instant message psychic readings psychic readings chat
    online gordon smith medium psychic barber psychic help characteristics psychic
    person can psychics predict future relationships psychic meaning
    of owls how to test if you’re psychic your psychic
    develop your psychic abilities book psychic readings in gillingham kent psychic assassin taromaru download lisa
    marie psychic australia ann fisher psychic psychics victoria bc
    boston psychic studio boston ma psychic website free psychic town new york psychic answers free psychic media ltd california psychics pisces psychic picture cards be psychic course free download how to strengthen your psychic abilities
    psychic nancy myer the daily edition psychic sally latest psychic
    predictions for mh370 psychic readings st peters mo psychic
    mediums in nyc psychic tia show cancelled a good psychic reading california psychic pilar free online psychic reading no charge
    psychic iq test free psychic readings by barbara phoenix az most credible psychics best psychic utah rose psychic psychic test games online luther psychic actress psychic mediums uk 7th sense psychic reviews one to one psychic readings essex

  10. 2018年6月14日03:05 | #10

    scaffolding accident lawyer
    Howdy! This blog post couldn’t be written any better! Reading through this post reminds me of my previous roommate!
    He constantly kept preaching about this. I’ll send this
    information to him. Pretty sure he’s going to have a very good read.
    Many thanks for sharing!

  11. 2018年6月15日04:17 | #11

    https://is.gd/RMGb6i- – Consume adequate quantity of nutrients,
    including fibers that lower cholesterol levels, heart-healthy
    nuts, fishes, and low-fat dairy full of calcium. Yoga: this ancient system of breathing and stretching postures may be known to provide respite from the multiple chronic disorders that plague
    most seniors. So far, exercise and balanced diets are
    considered as a couple of the main factors that lead to properly body.

  12. 2018年6月15日07:53 | #12

    click here to investigate
    As the admin of this website is working, no question very
    soon it will be famous, due to its quality contents.

  13. 2018年6月15日09:15 | #13

    It’s perfect time to make some plans for the future and it is time
    to be happy. I’ve read this post and if I could I wish to suggest you some
    interesting things or advice. Perhaps you can write next articles
    referring to this article. I wish to read even more things about it!
    https://profiles.wordpress.org/sinmolaws1/

  14. 2018年6月19日04:17 | #14

    My brother recommended I would possibly like this web site.
    He was entirely right. This submit truly made my day.

    You can not believe simply how a lot time I had spent for this info!
    Thanks! http://yallpo.com/node/3831

  15. 2018年6月21日13:24 | #15

    a fantastic read
    I have to thank you for the efforts you have put in penning this blog.
    I really hope to check out the same high-grade content
    from you later on as well. In fact, your creative writing abilities has motivated me to get my very
    own blog now ;)

  16. 2018年6月21日19:26 | #16

    test signe astrologique gratuit 17 septembre signe zodiaque signe
    astrologique le 24 octobre quel signe astrologique 21 mai signe du zodiaque 2 septembre correspondance astrologique
    homme femme quel est le signe astrologique du 22 juillet astrotheme astrologie chinoise signe astrologique definition cancer quel signe astrologique 21 mai signe
    astrologique de la semaine signification astrologie poisson 4 mai signe astrologique
    signe astrologique lion chinois signe astrologique 23 novembre portrait astrologique poisson ascendant sagittaire signe astrologique
    amour signe astrologique 15 mai signification signe astrologique
    taureau astrologie chinoise dragon de terre signe astrologique sagittaire ascendant balance
    signe astrologique nathaniel amour sucre signe du zodiaque lion homme
    calendrier signe astrologique 2017 caractere signe astrologique poisson signe astrologique et leur caractere signe astrologique du 25 novembre compatibilite
    tableau astrologie chinoise signe astrologique du 27 avril medaille signe astrologique argent
    decouvrez votre signe astrologique japonais tatouage signe
    astrologique belier chinois tigre feu astrologie chinoise signe zodiaque 19 aout mars en maison 5 astrologique trouver son ascendant
    astrologique belgique signe astrologique homme poisson femme balance signe zodiaque 4
    novembre 29 mai quel signe astrologique signe astrologique indien pendentif
    signe zodiaque chinois correspondance signes astrologiques signe astrologique 25 mars astrologie pour tous belier 12 signe
    astrologique date signes astrologiques 4 mars date de naissance signe astrologique chinois maisons egales en astrologie photo signe astrologique balance signe astrologique ascendant lion maisons astrologiques calcul

  17. 2018年6月21日20:20 | #17

    contactos sexo valencia video porno amateur maria valverde sexo peliculas pornografia gratis sexo romantico videos porno totalmente gratis ver peliculas porno en espanol gratis
    quedadas sexo madrid los mejores juegos porno sexo en andujar webcams de sexo porno abuelas espanolas cine
    porno gratis en espanol videos porno anales gratis videos porno
    viejos aplicaciones sexo posturas sexo embarazo porno
    con rubias sexo con mujeres viejas sexo anal placer cayetana guillen cuervo sexo porno gratis
    dibujos animados videos sexo animal porno
    lesbico xxx sexo oral con condon videos pornograficos hd videos pornos videos gratis
    sexo anal sexo peliculas porno sexo en nueva york capitulos porno esperanza gomez sexo casero maduro videos
    pornos youtube actores porno gays sexo en tu ciudad porno web cam videos de lesbianas
    porno sexo latina sexo usera porno brutal incestos
    porno gratis porno amater gratis pelicula porno con argumento porno espanol fakings porno gay xxx video de porno xxx porno male
    porno cruising gay video porno de cinthia fernandez sexo en nueva york
    youtube comic porno en espanol

  18. 2018年6月22日00:21 | #18

    tarot en linea por chat tarot justicia luna carta del
    tarot para hoy gratis terra tarot del dia gratis video
    tarot geminis semanal tarot gratis piscis septiembre tiradas tarot amor gratis carta tarot el mundo tarot oraculo amor llewelyn tarot tarot de
    verdadero amor tarot egipcio en femenino cartas
    gratis de tarot del amor tarot gratis acuario tarot futuro laboral
    gratis tarot del hada del amor el sol en tarot que significa tarot gratis para leo 2014 virgo tarot abril el tarot de la cruz celta gratis tarot
    del amor para libra tarot semanal libra gratis tarot gratis
    100 verdadero tarotista pedro engel tarot personal gratis tarot gitano
    verdadero gratis tarot de santos gratis astrocanal tarot del amor
    gratis tarot aprender gratis tirada del tarot gratis del amor si o no consulta tarot en vivo gratis
    tarot gratis de trabajo 2016 tarot rapido 3 minutos lectura de cartas de tarot pdf lectura de cartas del tarot gitano gratis tarot tirada gratis 3 cartas horoscopo del dia gratis cartas tarot sola
    busca tarot revisited rueda dela fortuna invertida en el amor tarot horoscopo diario arcanos lectura del tarot gratis si o no cartas del
    tarot gratis cartomancia horoscopo chino de hoy gratis rata tarot
    gratis salud pregunta tarot la rueda dela fortuna tarot significado tarot maya gratis 2017 videncia tarot gratis amor tarot mas barato la emperatriz tarot y gratis tipos de tiradas del tarot del amor

  19. 2018年6月22日00:46 | #19

    tirage tarot gemeaux tarot jouer l’excuse en premier tarot gratuit en ligne tirage en croix tarot gratuit fiable
    tarot virtuel prediction tarot a 3 poignee interpretation carte tarot jeux tarot flash tarot
    lame 7 tarot l’etoile et le pendu tarot gratuit amour travail finance tirage tarot osho tarot amour fiable gratuit
    en ligne interpretation tarot tirage en croix combinaison carte tarot imperatrice
    tirage tarots divinatoire gratuit le meilleur
    tarot gratuit en ligne amour voyance tarot gratuit jeu ordinaire tirage tarot gratuit
    famille regle tarot excuse au bout rune tarot oracle astro tarot
    gratuit tirage carte tarot travail tarot gratuit du jour astrocenter tarot imperatrice et force tarot persan amour jouet au tarot gratuit tarot en ligne
    sans inscription gratuit tarot travail tarot soleil abonnement
    tarot fiable et serieux regle tarot a 5 excuse tirage
    tarot gitan tarots amours gratuits signification carte tarot
    persan tirage tarot gratuit oui non tarot persan interpretation tarot
    jouer a 2 tarot croise divinatoire interpretation tarot avec tirage gratuit comment
    lire l’avenir dans le tarot tarot atouts signification voyance en ligne gratuite tarot allo tarot carte du jour comment lire le tarot gratuit tarot astrologique interpretation voyance tarot en ligne soleil tarot envers tirage tarot
    oracle bleu tirage tarot carte a jouer tarot simple

  20. 2018年6月23日11:31 | #20

    If you are heading for another city and locate that there is a good show in that city, you can not search around for
    that box office, stand it a line and purchase the tickets.

    Warrior bands moved south and east towards the rich pickings of the peoples whom that they had traded with.
    The Open Video Project: This is site using a huge assortment of
    digital video for sharing.

  21. 2018年6月24日01:52 | #21

    viagra without a doctor prescription
    viagra without prescription
    viagra without prescription
    viagra without a doctor
    viagra without prescription

  22. 2018年7月5日02:35 | #22

    I every time used to read article in news papers but now as I am a user of net therefore from now
    I am using net for content, thanks to web. http://uremily1vlog.soup.io/post/658588158/Personal-Injury-Claims-Frequently-Asked-Questions-in

  23. 2018年7月13日14:26 | #23

    Useful info. Lucky me I found your web site accidentally, and I’m stunned why this accident didn’t came about earlier!
    I bookmarked it.

  24. 2018年7月13日14:49 | #24

    photo sexi porno fille qui mouille sexe amateur photos fart porno indienne
    sex annonce sex caen film porno en entier video
    porno xxl photo couple sex photo sex porno hd amateur porno sexe etudiantes porno famme salope sex porno classic massage sexe femme
    jeux sex piercing sexe femme porno lesbien gratuit web cam
    porno photo sexe video gratuit de sex nature sexe
    chat webcam sexe gros sexe homme sexe tags video porno
    secretaire sexe poitiers hotesse porno extraits de films porno video sexe
    pute porno gay video film porno pussy les coulisses
    du porno porno sex arab petite video porno gratuit facial sex porno suceuse sexe noir photos sexe feminin porn amateur cam beurrette porno sexe teen video
    teen black porno milf porno hd doctor porno hd porno cash chti porno femme nue
    et sexi reportage sex kim kardashian sexe

  25. 2018年7月13日18:49 | #25

    plan cul vauvert plan cul roquebrune cap martin plan cul merignac plan cul
    yzeure plan cul lagny sur marne plan cul vaucluse plan cul lyon sans inscription plan cul forum cherche homme plan cul plan cul parthenay les plans cul plan cul le gosier plan cul
    a lorient plan cul cotes d’armor plan cul femme mature
    plan cul arles plan cul challans femme plan cul plan cul thionville plan cul
    gratuit lyon plan cul tournon sur rhone site plan cul totalement gratuit plan cul gueret meilleur
    site pour plan cul plan cul avec trans plan cul charenton le
    pont plan cul arnouville les gonesse plan cul alger plan cul mougins plan cul saint flour
    plan cul haguenau plan cul 15 plan cul cher plan cul sainte foy les lyon plan cul riorges plan cul
    saint pierre des corps plan cul rouen gratuit plan cul landerneau homme cherche femme
    pour plan cul plan cul hem plan cul avec maman plan cul sur paris gratuit plan cul centre val de loire plan cul
    62 plan cul douarnenez plan cul 41 plan cul etudiantes plan cul grasse plan cul grande synthe
    plan cul en lorraine plan cul saint julien en genevois

  26. 2018年7月14日01:13 | #26

    What’s up Dear, are you in fact visiting this web site daily, if so afterward you will without doubt obtain fastidious know-how.

  27. 2018年7月14日17:45 | #27

    Can you tell us more about this? I’d like to find out some additional information. http://www.mediamax.sk/reklamne-plochy/node/351112

  28. 2018年7月14日18:26 | #28

    Yes! Finally something about seo expert.

  29. 2018年7月17日03:01 | #29

    I am extremely impressed with your writing skills and also with the
    layout on your blog. Is this a paid theme or did you modify it yourself?

    Either way keep up the nice quality writing, it’s
    rare to see a great blog like this one today.

  30. 2018年7月19日03:34 | #30

    888 casino no deposit bonus code
    gala casino 400 bonus
    new online casino march 2016
    online roulette limits
    9ja bet online

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