【问题标题】:How to use memcached (installed in different server) in php如何在php中使用memcached(安装在不同的服务器上)
【发布时间】:2016-10-27 05:41:13
【问题描述】:

我在 ubuntu 16 中使用 PHP-7 和 MySQL 安装了 memcached,我的 Web 应用程序在我使用 PHP-5 安装 xampp 的 Windows 中。

我想在 Windows 中的 Web 应用程序中使用安装在 ubuntu 中的 memcached。

有可能吗?

【问题讨论】:

标签: php mysql windows ubuntu memcached


【解决方案1】:

您需要使用addServer 方法将您的服务器添加到memcached 服务器池。

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

更多信息请查看 PHP 手册中的Memcached::addServer

【讨论】:

  • 这在第 2 行给出错误:Fatal error: Class 'Illuminate\Cache\Memcache' not found
  • id 不应该是Memcached,以d结尾吗?
  • @Ajay 可能是命名空间问题,请使用 $m = new \Memcached();
【解决方案2】:

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);
?>

更多信息: PHP:Memcached

在此之后不要忘记更改 /etc/memcached.conf (Ubuntu)

# 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

-l 0.0.0.0

然后

/etc/init.d/memcached restart

【讨论】:

  • Memcached 在 ubuntu 中运行良好,但我无法在另一台服务器上使用它的服务。因此不需要这些更改。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-06
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
  • 2022-04-20
  • 2013-01-24
  • 1970-01-01
相关资源
最近更新 更多