{"id":3986,"date":"2011-02-14T10:11:21","date_gmt":"2011-02-14T15:11:21","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=3986"},"modified":"2011-02-14T10:11:21","modified_gmt":"2011-02-14T15:11:21","slug":"memcache-vs-php-memcache","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/","title":{"rendered":"Memcache vs PHP Memcache"},"content":{"rendered":"<p>or Memcache vs. Memcached<\/p>\n<p>It seems that PHP has two memcached libraries named memcache and memcached. What is the difference and how do you know which one to use?  The newer memcached PHP extension was created recently by some guys at Digg. It has some new features and performance enhancements.<\/p>\n<p>Here is a quick backgrounder in naming conventions (for those unfamiliar), which explains the frustration by the question asker: For many *nix applications, the piece that does the backend work is called a &#8220;daemon&#8221; (think &#8220;service&#8221; in Windows-land), while the interface or client application is what you use to control or access the daemon. The daemon is most often named the same as the client, with the letter &#8220;d&#8221; appended to it. For example &#8220;imap&#8221; would be a client that connects to the &#8220;imapd&#8221; daemon.<\/p>\n<p>This naming convention is clearly being adhered to by memcache when you read the introduction to the memcache module (notice the distinction between memcache and memcached in this excerpt):<\/p>\n<p>Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.<\/p>\n<p><!--more--><\/p>\n<p>The Memcache module also provides a session handler (memcache).<\/p>\n<p>More information about memcached can be found at<br \/>\n<a href=\"http:\/\/www.danga.com\/memcached\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.danga.com\/memcached\/<\/a>.<\/p>\n<p>The frustration here is caused by the author of the PHP extension which was badly named memcached, since it shares the same name as the actual daemon called memcached. Notice also that in the introduction to memcached (the php module), it makes mention of libmemcached, which is the shared library (or API) that is used by the module to access the memcached daemon:<\/p>\n<p>memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.<\/p>\n<p>This extension uses libmemcached library to provide API for communicating with memcached servers. It also provides a session handler (memcached).<\/p>\n<p>Information about libmemcached can be found at<br \/>\n<a href=\"http:\/\/libmemcached.org\/libMemcached.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/tangent.org\/552\/libmemcached.html<\/a>.<\/p>\n<p>In summary, both are functionally the same, but they simply have different authors, and the one is simply named more appropriately than the other.<\/p>\n<p>The most important features that memcached has are:<\/p>\n<li>Cas tokens. Whenever you pull something from the cache, you can receive with it a cas token (a double number). You can than use that token to save your updated object. If no one else updated the value while your thread was running, the swap will succeed. Otherwise a newer cas token was created and you are forced to reload the data and save it again with the new token.<\/li>\n<li>Read through callbacks are the best thing since sliced bread. It has simplified much of my code.<\/li>\n<li>getDelayed() is a nice feature that can reduce the time your script has to wait for the results to come back from the server.<\/li>\n<li>While the memcached server is supposed to be very stable, it is not the fastest. You can use binary protocol instead of ASCII with the newer client.\n<\/li>\n<li>Whenever you save complex data into memcached the client used to always do serialization of the value (which is slow), but now with memcached client you have the option of using igbinary. So far I haven&#8217;t had the chance to test how much of a performance gain this can be.\n<p><strong>Create a temporary folder<\/strong><br \/>\n1. As it is a manually work, you might want to clear the source file after the installation, so create a folder as command below.<br \/>\n<code><br \/>\nmkdir ~\/memcache<br \/>\n<\/code><\/p>\n<p><strong>Install LibEvent<\/strong><br \/>\nTo install memcache, you will need LibEvent, go to their site to get the latest version.<\/p>\n<p><code><br \/>\ncd ~\/memcache<br \/>\nwget http:\/\/monkey.org\/~provos\/libevent-1.4.14b-stable.tar.gz<br \/>\ntar zxvf libevent-1.4.14b-stable.tar.gz<br \/>\ncd libevent-1.4.14b-stable<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<br \/>\n<\/code><\/p>\n<p><strong>Install Memcache<\/strong><br \/>\nNow, install the memcache and get the latest version from their site.<br \/>\n<code><br \/>\ncd ~\/memcache<br \/>\nwget http:\/\/memcached.googlecode.com\/files\/memcached-1.4.5.tar.gz<br \/>\ntar zxvf memcached-1.4.5.tar.gz<br \/>\ncd memcached-1.4.5<br \/>\n.\/configure --with-lib-event=\/usr\/local\/<br \/>\nmake<br \/>\nmake install<br \/>\n<\/code><\/p>\n<p><strong>Install PHP Memcache<\/strong><br \/>\nNow, install PECL Memcache and get the latest version.<br \/>\n<code><br \/>\ncd ~\/memcache<br \/>\nwget http:\/\/pecl.php.net\/get\/memcache-2.2.6.tgz<br \/>\ntar zxvf memcache-2.2.6.tgz<br \/>\ncd memcache-2.2.6<br \/>\nphpize<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<br \/>\nvi \/usr\/local\/lib\/php.ini<br \/>\n<\/code><\/p>\n<p><strong>Find the extension<\/strong> as below and if it is not existed, add it in the php.ini.<br \/>\n<code><br \/>\nextension=memcache.so<\/code><\/p>\n<p><strong>Restart the Apache services<\/strong>.<br \/>\n<code><br \/>\nservice httpd restart<br \/>\n<\/code><\/p>\n<p>A good comparison of the 2 versions is here:<br \/>\n<a href=\"http:\/\/code.google.com\/p\/memcached\/wiki\/PHPClientComparison\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/code.google.com\/p\/memcached\/wiki\/PHPClientComparison<\/a><\/li>\n","protected":false},"excerpt":{"rendered":"<p>or Memcache vs. Memcached It seems that PHP has two memcached libraries named memcache and memcached. What is the difference and how do you know which one to use? The newer memcached PHP extension was created recently by some guys at Digg. It has some new features and performance enhancements. Here is a quick backgrounder&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-3986","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Memcache vs PHP Memcache - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Memcache vs PHP Memcache - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"or Memcache vs. Memcached It seems that PHP has two memcached libraries named memcache and memcached. What is the difference and how do you know which one to use? The newer memcached PHP extension was created recently by some guys at Digg. It has some new features and performance enhancements. Here is a quick backgrounder... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2011-02-14T15:11:21+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Memcache vs PHP Memcache\",\"datePublished\":\"2011-02-14T15:11:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/\"},\"wordCount\":668,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/\",\"name\":\"Memcache vs PHP Memcache - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2011-02-14T15:11:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/memcache-vs-php-memcache\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Memcache vs PHP Memcache\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Memcache vs PHP Memcache - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/","og_locale":"en_US","og_type":"article","og_title":"Memcache vs PHP Memcache - Linux Shtuff","og_description":"or Memcache vs. Memcached It seems that PHP has two memcached libraries named memcache and memcached. What is the difference and how do you know which one to use? The newer memcached PHP extension was created recently by some guys at Digg. It has some new features and performance enhancements. Here is a quick backgrounder... Read More","og_url":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2011-02-14T15:11:21+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Memcache vs PHP Memcache","datePublished":"2011-02-14T15:11:21+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/"},"wordCount":668,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/","url":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/","name":"Memcache vs PHP Memcache - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2011-02-14T15:11:21+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/memcache-vs-php-memcache\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Memcache vs PHP Memcache"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=3986"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3986\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=3986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=3986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=3986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}