Rumah > pembangunan bahagian belakang > tutorial php > php5-memcached比php5-memcache速度略快一点

php5-memcached比php5-memcache速度略快一点

WBOY
Lepaskan: 2016-07-29 09:05:54
asal
1031 orang telah melayarinya

??

php5-memcached比php5-memcache速度略快一点

php5-memcached和php5-memcache是两个php操作memcached的组件,他们是不同人开发的。

php官网都列出了他们各自的使用方法:

  • http://www.php.net/manual/en/book.memcache.php (安装使用:sudo apt-get install php5-memcache)
  • http://www.php.net/manual/en/book.memcached.php (安装使用:sudo apt-get install php5-memcached)
  • 1. 首先,先安装下apache:

    sudo apt-get update
    sudo apt-get install apache2

    2. 然后安装下php5:

    sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

    3. 接着安装memcached:

    sudo apt-get install memcached

    4. 接着安装php5-memcached和php5-memcache:

    sudo apt-get install php5-memcache

    sudo apt-get install php5-memcached

    5. 最后重启下apache2:

    sudo service apache2 restart

    6.编辑test.php内容如下:

    <span><?php // Initialize values: 10000 keys of 20 bytes with 40 bytes of data
    $c = 10000;
    $values = array();
    for ($i=0;$i<$c;$i++) $values[sprintf('%020s',$i)]=sha1($i);
    echo "memcache vs memcached: $c keys\n";
    
    // Memcached
    $m = new Memcached();
    $m->addServer('localhost', 11211);
    $start = microtime(true);
    foreach ($values as $k => $v) $m->set($k, $v, 3600);
    $time = microtime(true)-$start;
    echo "memcached set: $time\n";
    $start = microtime(true);
    foreach ($values as $k => $v) $m->get($k);
    $time = microtime(true)-$start;
    echo "memcached get: $time\n";
    
    // Memcache
    $m = new Memcache();
    $m->addServer('localhost', 11211);
    $start = microtime(true);
    foreach ($values as $k => $v) $m->set($k, $v, 0, 3600);
    $time = microtime(true)-$start;
    echo "memcache set: $time\n";
    $start = microtime(true);
    foreach ($values as $k => $v) $m->get($k);
    $time = microtime(true)-$start;
    echo "memcache get: $time\n";
    ?></span>
    Salin selepas log masuk

    7. 运行http://machinename/test.php 或者 php /var/www/html/test.php

    root@machinename  # php /var/www/html/test.php
    memcache vs memcached: 10000 keys
    memcached set: 0.7015380859375
    memcached get: 0.61220598220825
    memcache set: 0.78830289840698
    memcache get: 0.74954390525818

    ~
    root@machinename  # php /var/www/html/test2.php
    memcache vs memcached: 10000 keys
    memcache set: 0.78771591186523
    memcache get: 0.75219798088074
    memcached set: 0.69968199729919
    memcached get: 0.60679888725281

    参考文档:

    1.https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

    2. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-memcache-on-ubuntu-14-04

    3. https://www.leaseweb.com/labs/2013/03/memcache-vs-memcached-php-benchmark/

    以上就介绍了php5-memcached比php5-memcache速度略快一点,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

    Label berkaitan:
    sumber:php.cn
    Kenyataan Laman Web ini
    Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
    Tutorial Popular
    Lagi>
    Muat turun terkini
    Lagi>
    kesan web
    Kod sumber laman web
    Bahan laman web
    Templat hujung hadapan