Thursday, February 21, 2013

Solved: How to check if memcache or memcached is installed and running or not on Server Using PHP

After doing some R&D I figured out how to fix the issue with memcache installtion or class

many time we got the following message, If memcahed server is not running.

Memcache::connect(): Server localhost (tcp 11211) failed with: Connection refused

To fix the following issue I written the following Code

if(class_exists('Memcache') && extension_loaded('memcache') && function_exists('memcache_<div dir="ltr"><wbr />connect')) { //Checks on Server Memcache is installed or not$memcache = new Memcache();         $connection = @fsockopen('localhost', 11211); //Check port is open and forwarded using fsockopenif (is_resource($connection)) {$isMemcacheAvailable = $memcache->connect('localhost'<wbr />, 11211);             $cache->setMemcache($memcache)<wbr />;} else {error_log('Memcache Server is not running');}} else {error_log('Memcache is not installed on your Server');     }if ($isMemcacheAvailable) {$aData = $memcache->get('data');}

Above code will solve every issue.


Source : digcms[dot]com

0 comments:

Post a Comment