Memcached is a very popular caching service that we can use as aWordPress Object Cachingcan also be used as the server side of theCachify Static CacheAfter installing the Memcached service on the server, we also need to install the Memcached extension so that the PHP program can connect to the Memcahed service.
How to Install Memcached Extension in cPanel
In cPanel, we can easily install the Memcached extension from the command line.
For Centos-like Linux, we use the following command to install.
yum install ea-phpXX-php-memcached
For Debian-like systems, we use the following command to install.
apt-get install ea-phpXX-php-memcached
Once the installation is complete, restart php-fpm with the following command and you're good to go.
/scripts/restartsrv_apache_php_fpm --status
If you are using the lnmp or pagoda panel configuration environment, they also provide a very convenient tool to help us install PHP extensions, directly using the corresponding tool to install can be.
Determining if php-fpm is installed successfully
After performing the above installation steps, we can write a simple program to determine if php-fpm was installed successfully.
$memcache = new Memcached();
$memcache->addServer('localhost', 11211);
if ($memcache->set('test_key', 'Hello World')) {
echo "Connection successful, writing test data successful\n"; echo "Reading data: 'test_key', 'Hello World'"; if ($memcache->set('test_key', 'Hello World')
echo "Reading data: " . $memcache->get('test_key');
} else {
echo "Connection Failed"; } else { echo "Connection Failed".
}
Run the above code, if the display is "Connection Successful...", it means that our PHP environment can use Memcached service normally, so we can use Memcached to optimize and accelerate our WordPress.