|  
도움말

GoDaddy 도움말

Testing the functionality of Memcache using PHP

Memcache is a great tool to use to speed up your website. This article will show you how to test the functionality of memcache using a simple php script.
DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 15-30+ min
RELATED PRODUCTS Linux-based VPS or dedicated servers

This article will show you how to test the functionality of memcache using a php script. If you do not have memcache installed, please see one of these supporting articles.

How to install Memcache on CentOS

How to install Memcache on Ubuntu

For the example, we will be using an Ubuntu server, and testing the script from the default document root; the file name will be memcache_test.php.

To begin change directory to the document root:

cd /var/www/html/

Then, lets create a new file and call it memcache_test.php

vi memcache_test.php

In this example we are using vi, but you can use vim or nano

Using this snippet of code you can test the functionality of memcache, we have included error reporting to provide troubleshooting steps if your code does not work.

error_reporting(E_ALL|E_STRICT);

ini_set('display_errors', true);

$mem = new memcached();

$mem->addServer("127.0.0.1", 11211);

$result = $mem->get("Test");

if ($result) {

echo $result;

} else {

echo "Test key not found, adding key";

$mem->set("Test", "I found a match, memcache is working") or die("Nothing Saved...");

}

?>

To test the code, simply visit your servers IP in the browser followed by the file name:

127.0.0.1/memcache_test.php

If the script worked, you should see Test key not found, adding key. On refresh it should say I found a match, memcache is working

Congratulations, you have successfully verified that memcache is working.


이 글이 도움되었나요?
피드백을 보내주셔서 감사합니다. 고객 서비스 담당자에게 문의하시려면 지원 전화 번호 또는 위의 채팅 옵션을 이용하시기 바랍니다.
도와드릴 수 있어 기쁩니다! 더 도와 드릴 것이 있나요?
그것 유감스럽습니다. 혼동이 되었던 사항 또는 솔루션이 고객님의 문제를 해결하지 못했던 원인을 알려주세요.