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

來源:互聯網
上載者:User

php5-memcached比php5-memcache速度略快一點
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內容如下:

 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";?>

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/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.