简体   繁体   English

如何在PHP中使用memcached(安装在其他服务器中)

[英]How to use memcached (installed in different server) in php

I have installed memcached in ubuntu 16 with PHP-7 and MySQL and my web application is in windows where I installed xampp with PHP-5. 我已经使用PHP-7和MySQL在ubuntu 16中安装了memcached,并且我的Web应用程序是在Windows中使用PHP-5安装xampp的。

I want to use memcached installed in ubuntu from my web application in windows. 我想从Windows中的Web应用程序使用ubuntu中安装的memcached。

Is it possible? 可能吗?

You need to add your server to memcached server pool with addServer method. 您需要使用addServer方法将服务器添加到memcached服务器池中。

<?php
    $m = new Memcached();
    $m->addServer('UBUNTU_SERVER_IP', 11211);
?>

for more information please check Memcached::addServer on PHP Manual 有关更多信息,请在PHP手册上检查Memcached :: addServer

Example from PHP Manual: PHP手册中的示例:

<?php
$m = new Memcached();

/* Add 2 servers, so that the second one
   is twice as likely to be selected. */
$m->addServer('mem1.domain.com', 11211, 33);
$m->addServer('mem2.domain.com', 11211, 67);
?>

More informations: PHP:Memcached 更多信息: PHP:Memcached

After this don't forget to change in /etc/memcached.conf (Ubuntu) 在此之后,不要忘记在/etc/memcached.conf )中进行更改

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1

to

-l 0.0.0.0

and then 接着

/etc/init.d/memcached restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM