{"id":994,"date":"2018-10-20T19:41:01","date_gmt":"2018-10-20T19:41:01","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=994"},"modified":"2018-10-23T01:15:55","modified_gmt":"2018-10-23T01:15:55","slug":"how-to-save-php-sessions-in-memcached","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/20\/how-to-save-php-sessions-in-memcached\/","title":{"rendered":"How to Save PHP Sessions in Memcached"},"content":{"rendered":"<p>Memcached is a high performance storage engine designed for storing chunks for data, so it is great for storing sessions in it. The upside of doing this you notice a performance benefit from not writing these disk or a database is that you gain a performance increase. The downside is that memcached isn\u2019t saving anything, so if memcached restarts all of the users will need to login again.<\/p>\n<p>This guide assumes you have a working installation. If you do not please see <a href=\"https:\/\/linuxadmin.io\/install-memcached-on-centos\/\">How to install Memcached.<\/a><\/p>\n<h2>Configure PHP for Memcache<\/h2>\n<p>Make sure the memcache PHP extension is installed<\/p>\n<p>php -i|grep memcache<\/p>\n<p>If nothing returns go ahead and install it:<\/p>\n<p>pecl install memcache<\/p>\n<p>Find the location of your php.ini<\/p>\n<p># php -i|grep &#8220;Loaded Configuration File&#8221;<br \/>\nLoaded Configuration File =&gt; \/usr\/local\/php7\/etc\/php.ini<\/p>\n<p>Open the php.ini file and add the following line at the top:<\/p>\n<p>extension=&#8221;memcache.so&#8221;<\/p>\n<h2>Configure PHP To Store Session Data In Memcached<\/h2>\n<p>You will want to edit your php.ini again and find the following lines:<\/p>\n<p>session.save_handler =<br \/>\nsession.save_path =<\/p>\n<p>You will then want to update them to the following and uncomment them:<\/p>\n<p>session.save_handler = memcache<br \/>\nsession.save_path = &#8216;tcp:\/\/127.0.0.1.1:11211&#8217;<\/p>\n<p>The reason we selected the PHP extension memcache vs memcached, is that the memcached extension is not available in PHP 7. Go ahead and save the file.<\/p>\n<p>Restart your webserver<\/p>\n<p>service nginx restart<\/p>\n<p>or<\/p>\n<p>service httpd restart<\/p>\n<p>And your session data should now be stored in memcached<\/p>\n<p>Aug 6, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/storing-php-sessions-in-memcached\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Memcached is a high performance storage engine designed for storing chunks for data, so it is great for storing sessions in it. The upside of doing this you notice a performance benefit from not writing these disk or a database is that you gain a performance increase. The downside is that memcached isn\u2019t saving anything, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/20\/how-to-save-php-sessions-in-memcached\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Save PHP Sessions in Memcached&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-994","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=994"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":1394,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/994\/revisions\/1394"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}