【问题标题】:Using memcache inside Google Compute Engine with PHP通过 PHP 在 Google Compute Engine 中使用 memcache
【发布时间】:2015-07-20 00:19:06
【问题描述】:

我正在尝试使用 App Engine 的 Memcache 和我们在 Compute Engine 下运行的服务器进行测试。目前我们只有几个运行 Memcache 的 VM 实例:

$memcache->addServer('memcache', 11211);

引用每个服务器。查看 Google 的示例代码,它没有提及我们应该调用什么服务器。我试图从他们的文档中测试以下代码,但在创建对象时出错。我知道我可能必须包含一个类,但它没有提到文档中的任何内容或要调用的服务器。有人可以帮忙吗?

<?php

header('Content-Type: text/plain');

echo "Setting Value\n";
$memcache = new Memcached;

echo "Get who value<br>";
$who = $memcache->get('who');

echo 'Previously incremented by ' . $who . "\n";
$memcache->set('who', 'PHP');

$count = $memcache->increment('count', 1, 0);
echo 'Count incremented by PHP = ' .  $count . "\n";

【问题讨论】:

  • App Engine 和computer engine 是不同的产品,不共享同一个memcache 服务器。
  • @BradWickwire 如果您找到解决问题的方法,您会告诉我们吗?

标签: php google-app-engine memcached google-compute-engine


【解决方案1】:

Google App Engine 提供托管的 Memcache 服务,而 Google Compute Engine 不提供。

在 App Engine 上,App Engine 上运行的应用会自动连接到服务器,这意味着您无需在应用中指定主机/端口。

但是,在 Compute Engine 上,如果您想使用 memcache,则需要在与您的应用程序相同或不同的 VM 中运行您自己的 memcached 服务器,并在您的 PHP 客户端中指定其主机/端口。

PHP 提供了两个类来连接 memcached:

每个都提供了一种方法来指定要连接的服务器,例如,

但运行这些 memcached 服务器仍取决于您。

【讨论】:

    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 2013-10-09
    • 2015-02-19
    • 2019-03-14
    • 2017-06-29
    • 2016-10-27
    • 2018-05-01
    • 1970-01-01
    相关资源
    最近更新 更多