在Google Compute Engine中使用PHP中的memcache [英] Using memcache inside Google Compute Engine with PHP

查看:111
本文介绍了在Google Compute Engine中使用PHP中的memcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用App Engine的Memcache测试我们在计算引擎下运行的服务器。目前我们只有几个运行Memcache的虚拟机实例,我们称之为:

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

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

<?php

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

回显设定值\ n;
$ memcache = new Memcached;

echo获取谁值< br>;
$ who = $ memcache-> get('who');

echo'以前由'递增'。 $谁。 \\\
;
$ memcache-> set('who','PHP');

$ count = $ memcache-> increment('count',1,0);
echo'计数递增PHP ='。 $ count。 \\\
;


解决方案

Google App Engine提供托管的Memcache服务,Google Compute引擎不会。



在App Engine上,自动为App Engine上运行的应用程序连接服务器,这意味着您无需指定主机/ port在应用程序中。



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



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



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



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


I am trying to test using App Engine's Memcache with our servers running under Compute Engine. Currently we just have a couple VM instances which run Memcache where we call:

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

to reference each server. Looking at Google's sample code, it doesn't mention anything about what server we should call. I tried to test the below code from their document but it errors on creating the object. I understand that I might have to include a class, but it didn't mention anything in the document or what server to call. Can anyone help?

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

解决方案

Google App Engine provides a hosted Memcache service while Google Compute Engine does not.

On App Engine, the connection to the server is made automatically for the app running on App Engine, which means you don't need to specify a host/port in the app.

On Compute Engine, however, if you want to use memcache, you will need to run your own memcached server, either in the same or different VM as your application, and specify its host/port in your PHP client.

PHP provides two classes to connect to memcached:

Each provides a method to specify server(s) to connect to, e.g.,

but it's still up to you to run these memcached servers.

这篇关于在Google Compute Engine中使用PHP中的memcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆