Home >Backend Development >PHP Tutorial >Installation and configuration method of ubuntu memcached in php

Installation and configuration method of ubuntu memcached in php

一个新手
一个新手Original
2017-09-06 15:30:311446browse

# 安装服务端
sudo apt-get install memcached
#启动服务
memcached -d -m 128 -p 11111 -u root

Download php memcached.dll under window

http://pecl.php.net/package/memcache/3.0.8/windows

Next configure PHP

Copy php_memcache.dll to the PHP extension folder, add a line in the php.ini file

extension=php_memcache.dll

Restart the web server, check phpinfo, if there is memcached content, it means that PHP configuration is successful.

You can use the following program to test whether the installation is successful:

header('Content-type: text/html; charset=utf-8');
$memcache = memcache_connect('192.168.0.156', 11111);
if ($memcache) {    
    $memcache->set("str_key", "String to store in memcached");    
    $memcache->set("num_key", 123);    
    $object = new StdClass;    
    $object->attribute = 'test';    
    $memcache->set("obj_key", $object);    
    $array = Array('assoc'=>123, 345, 567);    
    $memcache->set("arr_key", $array);    
    var_dump($memcache->get('str_key'));    
    var_dump($memcache->get('num_key'));    
    var_dump($memcache->get('obj_key'));
}else {    
    echo "Connection to memcached failed";
}

The above is the detailed content of Installation and configuration method of ubuntu memcached in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn