Php5-memcached is a little bit faster than Php5-memcache.

Source: Internet
Author: User
Tags memcached php website

?? Php5-memcached is a little bit faster than Php5-memcache.


Php5-memcached and Php5-memcache are the components of two PHP operations memcached, which are developed by different people.

The PHP website lists their respective use methods:

  • http://www.php.net/manual/en/book.memcache.php (Installation using: sudo apt-get install php5-memcache)
  • http://www.php.net/manual/en/book.memcached.php (Installation using: sudo apt-get install php5-memcached)
  • 1. First, install the Apache first:

    sudo apt-get update
    sudo apt-get install apache2

    2. Then install the following php5:

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

    3. Then install the memcached:

    sudo apt-get install memcached

    4. Then install php5-memcached and Php5-memcache:

    sudo apt-get install Php5-memcache

    sudo apt-get install php5-memcached

    5. Finally restart the apache2:

    sudo service apache2 restart

    6. Edit the test.php content as follows:

    <?php//Initialize values:10000 keys of bytes with 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->se T ($k, $v, 0, 3600); $time = Microtime (True)-$start; echo "memcache set: $time \ n"; $start = Microtime (True); foreach ($values A s $k = $v) $m->get ($k), $time = Microtime (True)-$start; echo "memcache get: $time \ n";? 

    7. Run http://machinename/test.php or php/var/www/html/test.php

    [email protected] # 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

    ~
    [email protected] # 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

    Reference Documentation:

    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 is a little bit faster than Php5-memcache.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.