Home  >  Article  >  Backend Development  >  Detailed explanation of ubuntu memcached installation and configuration in php

Detailed explanation of ubuntu memcached installation and configuration in php

黄舟
黄舟Original
2017-09-06 09:22:021074browse


Detailed explanation of ubuntu memcached installation and configuration in php

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

Download php memcached.dll under window

Next configure PHP

Copy php_memcache.dll to the PHP extension folder, add a line

extension=php_memcache.dll

to the php.ini file, restart the web server, and check phpinfo. If there is memcached content, it means that the 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 Detailed explanation of ubuntu memcached installation and configuration 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