Table des matières
php使用memcached简单示例分享,phpmemcached示例
Maison développement back-end tutoriel php php使用memcached简单示例分享,phpmemcached示例_PHP教程

php使用memcached简单示例分享,phpmemcached示例_PHP教程

Jul 12, 2016 am 08:54 AM
多维数组

php使用memcached简单示例分享,phpmemcached示例

本文章简单向码农们介绍一下memcached。memcached 是高效、快速的分布式内存对象缓存系统,主要用于加速WEB动态应用程序。今天我和码农们先来简单探讨下memcached的用法。

1.添加memcached扩展包

1

<code class="hljs">php_memcache.dll</code>

Copier après la connexion

2.在PHP.INI添加memcached扩展

1

<code class="language-php hljs">extension=php_memcache.dll</code>

Copier après la connexion

3.程序

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

<?<span>php

    </span><span>//</span><span>创建一个mem对象实例</span>

    <span>$mem</span>=<span>new</span><span> Memcache;

    </span><span>if</span>(!<span>$mem</span>->connect("10.18.110.213",11211<span>)){

        </span><span>die</span>('连接失败!'<span>);

    }

    </span><span>//</span><span>增加

    //1.增加一个字串</span><span>

/*</span><span>    if($mem->set('key1',"beijing",MEMCACHE_COMPRESSED,60)){

        echo '添加ok';

    }</span><span>*/</span>

    <span>//</span><span>2.添加数值</span><span>

/*</span><span>    if($mem->set('key1',100,MEMCACHE_COMPRESSED,60)){

        echo '添加ok';

    }</span><span>*/</span>

    <span>//</span><span>3.添加数组

    //在添加数组是,根据需要. 希望序列号放入  ,

    //serialize<=>unserialize, 如果根据需要,也可以json_encode <=> json_decode</span>

    <span>$arr</span>=<span>array</span>("bj",'tj'<span>);

    </span><span>if</span>(<span>$mem</span>->set('key1',<span>$arr</span>,MEMCACHE_COMPRESSED,<span>time</span>()+31*3600*24<span>)){

        </span><span>echo</span> '添加数组ok99111'<span>;

    }

    </span><span>//</span><span>4.添加对象</span><span>

/*</span><span>    class Dog{

        public $name;

        public $age;

        public function __construct($name,$age){

            $this->name=$name;

            $this->age=$age;

        }

    }

    $dog1=new Dog('小狗',50);

    if($mem->set('key1',$dog1,MEMCACHE_COMPRESSED,60)){

        echo '添加对象ok';

    }</span><span>*/</span>

    <span>//</span><span>5.添加null 布尔值</span><span>

/*</span><span>    if($mem->set('key1',false,MEMCACHE_COMPRESSED,60)){

        echo '添加布尔ok';

    }</span><span>*/</span>

    <span>//</span><span>6. 资源类型放入.</span><span>

/*</span><span>    $con=mysql_connect("127.0.0.1","root","root");

    if(!$con){

        die('连接数据库失败');

    }

    var_dump($con);

    echo "<br/>";

    if($mem->set('key1',$con,MEMCACHE_COMPRESSED,60)){

        echo '添加资源ok';

    }</span><span>*/</span>

    <span>//</span><span>查询</span>

    <span>$val</span>=<span>$mem</span>->get('key1'<span>);

</span><span>//</span><span>修改

    //可以使用replace</span>

    <span>if</span>(<span>$mem</span>->replace("key11",'hello',MEMCACHE_COMPRESSED,60<span>)){

        </span><span>echo</span> 'replace ok'<span>;

    }</span><span>else</span><span>{

        </span><span>echo</span> 'replace no ok'<span>;

    }

    </span><span>//</span><span>删除</span>

    <span>echo</span> "<br/>"<span>;

    </span><span>if</span>(<span>$mem</span>->delete('key14'<span>)){

        </span><span>echo</span> 'key14 删除'<span>;

    }</span><span>else</span><span>{

        </span><span>echo</span> 'key14不存在'<span>;

    }</span>

Copier après la connexion

原文地址:http://www.manongjc.com/article/683.html

相关阅读:

php扩展模块memcached长连接使用方法分析

php模块memcached使用指南

PHP5.5在windows安装使用memcached服务端的方法

php Memcached的使用方法介绍

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1119775.htmlTechArticlephp使用memcached简单示例分享,phpmemcached示例 本文章简单向码农们介绍一下memcached。memcached 是高效、快速的分布式内存对象缓存系统,主要...
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Article chaud

Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD
Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Article chaud

Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD
Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Tags d'article chaud

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Programme Python pour multiplier deux matrices à l'aide de tableaux multidimensionnels Programme Python pour multiplier deux matrices à l'aide de tableaux multidimensionnels Sep 11, 2023 pm 05:09 PM

Programme Python pour multiplier deux matrices à l'aide de tableaux multidimensionnels

Parcours dimensionnel du tri de tableaux multidimensionnels PHP : d'une dimension à plusieurs dimensions Parcours dimensionnel du tri de tableaux multidimensionnels PHP : d'une dimension à plusieurs dimensions Apr 29, 2024 pm 09:09 PM

Parcours dimensionnel du tri de tableaux multidimensionnels PHP : d'une dimension à plusieurs dimensions

Comment combiner plusieurs tableaux en un seul tableau multidimensionnel en PHP Comment combiner plusieurs tableaux en un seul tableau multidimensionnel en PHP Jul 09, 2023 pm 01:08 PM

Comment combiner plusieurs tableaux en un seul tableau multidimensionnel en PHP

Comment utiliser la fonction array_walk_recursive en PHP pour effectuer des opérations récursives sur des tableaux multidimensionnels Comment utiliser la fonction array_walk_recursive en PHP pour effectuer des opérations récursives sur des tableaux multidimensionnels Jun 26, 2023 am 11:40 AM

Comment utiliser la fonction array_walk_recursive en PHP pour effectuer des opérations récursives sur des tableaux multidimensionnels

Un moyen efficace d'inverser un tableau PHP multidimensionnel Un moyen efficace d'inverser un tableau PHP multidimensionnel Apr 29, 2024 am 09:00 AM

Un moyen efficace d'inverser un tableau PHP multidimensionnel

Comment trier un tableau multidimensionnel en PHP Comment trier un tableau multidimensionnel en PHP Jul 07, 2023 pm 12:45 PM

Comment trier un tableau multidimensionnel en PHP

Comment parcourir un tableau multidimensionnel en PHP Comment parcourir un tableau multidimensionnel en PHP Jul 07, 2023 am 10:17 AM

Comment parcourir un tableau multidimensionnel en PHP

Discussion approfondie sur les tableaux PHP : analyse complète des tableaux multidimensionnels, des tableaux associatifs, etc. Discussion approfondie sur les tableaux PHP : analyse complète des tableaux multidimensionnels, des tableaux associatifs, etc. Mar 13, 2024 pm 02:36 PM

Discussion approfondie sur les tableaux PHP : analyse complète des tableaux multidimensionnels, des tableaux associatifs, etc.

See all articles