InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Site Performance tutorials

  • Chrome PageSpeed insights
  • Google custom search with lazy loading
  • Install and monitor memcache for php on Ubuntu
  • Internal vs external css
  • Javascript in header vs footer
  • PHP apc - setup and performance benchmarks
  • Php apc vs memcache
  • Using inline image for site performance
 
  • Home
  • > Tutorials
  • > Web Development
  • > Site Performance

How to install and monitor memcache for php on Ubuntu Linux

By admin | Last updated on Nov 1, 2015

Memcache is one of the most popular distributed memory based cache system. It can give excellent performance results if configured correctly. Its a good idea to monitor memcache server from memory usage and cache hits/misses perspective. Here are the some steps to install, configure and monitor memcached server:

  1. To install memcache for php on Ubuntu Linux run these commands:
    sudo apt-get install memcached
    sudo apt-get install php5-memcache
  2. The default memory cap is 64m. It can be changed by editing /etc/memcached.conf as shown below:
    # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
    # Note that the daemon will grow to this size, but does not start out holding this much
    # memory
    -m 64

    It may be better to put all you data in memory (if possible) and you may want to calculate the cap accordingly. E.g. for a wordpress site with 1000 blogs and 20K bytes page size per blog, a 20M memory will be able to hold all the posts. To take care of other pages (category, tags) and overheads, 40MB size should be good initial estimate.

  3. Install memcache.php stats script somewhere on your server. Copy etc/config.php to etc/config.local.php and change the username and password in config.local.php so that you can access it from the web interface with desired auth.
    define('ADMIN_USERNAME','memcache'); // Admin Username
    define('ADMIN_PASSWORD','SOME_PASSWORD'); // Admin Password
  4. Access http://yoursite.com/memcache.php (assuming it is installed at root location). Here is how the host stats looks like:
    memcache-host-cache-usage-hits-misses-statsYou may want to monitor cache usage. If there is no free space left, then there may be high cache churn and it may be bad for performance. Another thing to monitor is hits and misses. Its a good idea to have a high hits ratio. I think it should usually be higher than 80% unless the traffic on the site is very low. First visit on a page results in cache miss and subsequent visits results in cache hit. So for higher traffic the hit ratio is usually high assuming enough memory to hold all pages.
  5. You can also install libmemcached-tools (command line tools). Here is the install command for Ubuntu Linux:
    sudo apt-get install libmemcached-tools

    To dump a list of keys

    memcdump --servers=localhost

    To dump one specific key (ore more separated by space)

    memccat --servers=localhost w3tc_key_infoheap.com_0_pgcache_6c2156b977a576b022f2792b76c973a6_0
  6. To restart memcached (this will clear all cache also):
    sudo service memcached restart

Suggested posts:

  1. How to bypass cross site scripting (XSS) protection by browsers
  2. PHP echo – comma (,) vs dot (.) performance benchmarks
  3. PHP apc – setup and performance benchmarks on Ubuntu Linux
  4. Why and how to log Content-Type in apache access log
  5. migrate multiple mysql databases using mysqldump on Linux
  6. Php apc vs memcache
  7. How to upgrade EC2 Ubuntu Linux micro instance to small
  8. How to use pm2 to manage node.js application in production
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Memcache, PHP, Site Performance, Tutorials, Ubuntu Linux, Webmaster
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress