我是靠谱客的博主 柔弱香水,最近开发中收集的这篇文章主要介绍使用Windows Azure在云中托管PHP,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

More than a buzzword in executive meetings, cloud computing is the next big thing in the world of IT. Clouds offer an infinite amount of resources, both on demand and in pay-per-use models: computer resources on tap! In this article, I’ll focus on one of these cloud platforms, Microsoft’s Windows Azure, and give you all the information you need to get started developing PHP applications on this platform. Although we won’t go too deep into the technicalities, I will point you to further information and resources on specific points as we go.

云计算不仅是高管会议上的一个时髦词汇,而且是IT领域的下一件大事。 无论是按需还是按使用付费的模型,云都提供了无限量的资源:计算机资源随时可用! 在本文中,我将重点介绍这些云平台之一,即Microsoft的Windows Azure,并为您提供开始在该平台上开发PHP应用程序所需的所有信息。 尽管我们不会对技术进行太深入的介绍,但是在我们进行的过程中,我将为您指出特定点的更多信息和资源。

不同的云 (Different Clouds)

Choice is a good thing. The great news for us developers is that there are many choices when it comes to cloud computing. Microsoft, Google, Amazon, Rackspace, GoGrid, and many others offer cloud products that have their own special characteristics. It looks like the whole world is dividing these offers into two distinct categories: IaaS (Infrastructure-as-a-Service) and PaaS (Platform-as-a-Service)—the difference between the two is illustrated in Figure 1, “The difference between cloud platforms”.

选择是一件好事。 对于我们开发人员而言,好消息是,在云计算方面有很多选择。 微软,谷歌,亚马逊,Rackspace,GoGrid和许多其他公司提供具有自己特殊特征的云产品。 似乎全世界都在将这些优惠分为两个不同的类别: IaaS (基础设施服务)和PaaS (平台服务)—两者之间的区别如图1所示。云平台之间的差异”。

The difference between cloud platforms

云平台之间的区别

First, let’s look at IaaS. Amazon EC2 was the first to offer virtual machines that could run your application. These virtual machines, however, are under your control, like physical servers in your data center. This means that you’re in control of patches, security, maintenance to the operating system—and all with full root or administrator access. The cloud platform takes the infrastructure woes out of your hands, as networking, load balancers, and firewalls are handled for you.

首先,让我们看一下IaaS。 Amazon EC2是第一个提供可以运行您的应用程序的虚拟机的公司。 但是,这些虚拟机在您的控制之下,就像数据中心中的物理服务器一样。 这意味着您可以控制补丁程序,安全性,操作系统维护以及所有操作,并且具有完全的root或管理员访问权限。 由于为您处理了网络,负载平衡器和防火墙,因此云平台消除了基础架构的麻烦。

Next, there’s PaaS. This approach is also based on virtual machines,but you don’t have control over them. Instead, a set of tools and APIs is provided to let you package your application and upload it onto your virtual machine, so the only thing you have to worry about is your application. The networking, operating system, and so on are all maintained by the cloud platform.

接下来是PaaS。 这种方法也基于虚拟机,但是您无法控制它们。 相反,提供了一组工具和API,可让您打包应用程序并将其上传到虚拟机,因此您唯一需要担心的就是您的应用程序。 网络,操作系统等均由云平台维护。

All cloud vendors share common features, including virtual machines, and storage that’s available through REST-based protocols. Then again, each offering has its own unique features, which is good: clouds are still in a very innovative phase, and as developers we have the luxury of choosing the platform that’s best suited to our particular applications.

所有云供应商都共享通用功能,包括虚拟机和可通过基于REST的协议访问的存储。 再者,每种产品都有其独特的功能,这是件好事:云仍处于非常创新的阶段,作为开发人员,我们可以选择最适合我们特定应用程序的平台。

Windows Azure平台概述 (Windows Azure Platform Overview)

Throughout this article, I’ll be describing the Windows Azure Platform, Microsoft’s PaaS offering to the world of cloud computing. But before we dive into technical details, let’s get a feel for the components included in this offering, and what they do.

在整篇文章中,我将描述Windows Azure平台,这是Microsoft向云计算世界提供的PaaS产品。 但是,在深入探讨技术细节之前,让我们先了解一下此产品中包含的组件及其作用。

Windows Azure (Windows Azure)

Windows Azure is the core component of the Windows Azure Platform. The marketing folks describe this component as the “operating system for the Azure cloud.” I’m not a big fan of marketing folks and their quotes, but for once, they’re right! Windows Azure is the heart of Microsoft’s offering, and it does what you’d expect of any operating system: it allows you to run your application on a virtual machine, either in a web role (with a web server installed) or in a worker role—a cleaner virtual machine that allows you to host other types of applications.

Windows Azure是Windows Azure平台的核心组件。 市场营销人员将此组件描述为“ Azure云的操作系统”。 我不是行销人士及其报价的忠实拥护者,但有一次他们是对的! Windows Azure是Microsoft产品的核心,它可以完成任何操作系统的预期:它允许您在虚拟机上以Web角色(安装了Web服务器)或在工作程序中运行应用程序角色-一个更干净的虚拟机,允许您托管其他类型的应用程序。

Windows Azure also allows you to scale up rapidly: simply change a configuration value and you’ll have multiple instances running a the snap of your fingers. Load balancing is taken care of automatically and requires no configuration.

Windows Azure还允许您快速扩展:只需更改配置值,您就可以轻松运行多个实例。 负载平衡是自动进行的,不需要任何配置。

Next to the operating system, a set of storage services is included, which is accessible through a REST-based API. Blob storage allows you to host any file: text files, images, downloads, and more.

在操作系统旁边,包括一组存储服务,可通过基于REST的API访问这些存储服务。 通过Blob存储,您可以托管任何文件:文本文件,图像,下载文件等。

Table storage is, in essence, a document database that has limited querying possibilities but can scale massively. And then there are queues, which are mostly used for communications between web and worker roles.

从本质上说,表存储是一个文档数据库,其查询可能性有限,但可以大规模扩展。 然后是队列,这些队列主要用于Web和工作人员角色之间的通信。

Windows Azure is the location where your application will be hosted. A web role will host your web application; you’ll probably use blob storage to store files, and possibly table storage (or SQL Azure, which we’ll discuss in a moment) to store your data. Windows Azure is also used by other components of the platform.

Windows Azure是应用程序的托管位置。 网络角色将托管您的网络应用程序; 您可能会使用Blob存储来存储文件,并可能使用表存储(或我们稍后将讨论SQL Azure)来存储数据。 平台的其他组件也使用Windows Azure。

SQL Azure (SQL Azure)

In addition to hosting, you will probably need a place where you can store your relational data. This is where SQL Azure comes in: it’s a slightly modified version of Microsoft SQL Server that delivers all the services you’d expect from a database: tables, views, indexes, stored procedures, triggers, and so on.

除了托管之外,您可能还需要一个可以存储关系数据的地方。 这就是SQL Azure出现的地方:它是Microsoft SQL Server的略微修改版本,可提供您希望从数据库获得的所有服务:表,视图,索引,存储过程,触发器等。

SQL Azure provides database services in a scalable and reliable way. Data is replicated across different sites and made available through a load balancer, giving you a lot of performance on the data layer of your application.

SQL Azure以可伸缩且可靠的方式提供数据库服务。 数据跨不同站点复制,并通过负载平衡器提供,从而在应用程序的数据层上提供了很多性能。

Windows Azure平台AppFabric (Windows Azure Platform AppFabric)

Windows Azure Platform AppFabric is, in essence, a combination of two products. There’s an Access Control Service to which you can delegate the tasks of authentication and authorization of users, and there’s the Service Bus, which, in my opinion, is one of the features that really makes Windows Azure stand out. In short, the service bus allows you to establish communication between two endpoints. That might be a service that publishes messages to a set of subscribers, but the service bus can also be used for punching holes in firewalls!

Windows Azure平台AppFabric本质上是两种产品的组合。 有一个访问控制服务,您可以委派用户的身份验证和授权任务,还有服务总线,在我看来,这是使Windows Azure脱颖而出的功能之一。 简而言之,服务总线允许您在两个端点之间建立通信。 那可能是一种将消息发布给一组订户的服务,但是该服务总线也可以用于在防火墙上打Kong!

Imagine having applications A and B, each in different networks, behind different firewalls. No direct communication seems possible, yetthe AppFabric service bus will make sure both applications can communicate. There’s no need to open up ports in your company’s firewall to have your cloud application communicate with an on-premises application.

想象一下,将应用程序A和B分别位于不同的网络中,位于不同的防火墙之后。 似乎无法进行直接通信,但是AppFabric服务总线将确保两个应用程序都可以通信。 无需在公司的防火墙中打开端口即可让您的云应用程序与本地应用程序进行通信。

现场服务 (Live Services)

Live Services provides an online identity system that you probably already know: Windows Live ID. Live Services also offers features like presence awareness, search, mapping via Bing Maps, synchronization, and more.

Live Services提供了您可能已经知道的在线身份系统:Windows Live ID。 Live Services还提供诸如状态感知,搜索,通过Bing Maps进行地图绘制,同步等功能。

代号项目:达拉斯和悉尼 (Codename Projects: Dallas and Sydney)

These products are still in their incubation phases, and will probably undergo some changes in the future. Nevertheless, they already offer some great features. Dallas is basically a Data-as-a-Service solution through which you can subscribe to various sets of data offered in an open format, OData, which is based on REST and Atom. It also provides your business with a new source of revenue: if you’re sitting on a lot of useful data, why not make it available via Dallas and have others pay for using it?

这些产品仍处于孵化阶段,将来可能会发生一些变化。 尽管如此,它们已经提供了一些很棒的功能。 达拉斯基本上是一种“数据即服务”解决方案,通过它您可以订阅以REST和Atom为基础的开放格式OData提供的各种数据集。 它还为您的企业提供了新的收入来源:如果您拥有大量有用的数据,为什么不通过达拉斯提供这些数据,而让其他人为此付费呢?

Project Sydney is different: it’s focused on how you communicate with your cloud application. Currently, that communication is completed through the public Internet, but Sydney will allow you to set up a VPN connection to your virtual machines, enabling you to secure communications using your own security certificates and such.

悉尼项目与众不同:它专注于您与云应用程序进行通信的方式。 当前,该通信已通过公共Internet完成,但是Sydney将允许您建立与虚拟机的VPN连接,从而使您能够使用自己的安全证书等来保护通信。

适用于PHP的工具和API (Tools and APIs Available for PHP)

When we’re talking about using PHP in a cloud platform like Windows Azure, there are some objectives that we should fulfil before we start to work with the cloud. You’ll need the right tools to build and deploy your application, but also the right APIs—those that allow you to use the platform and all of its features.

当我们谈论在Windows Azure这样的云平台中使用PHP时,在开始使用云之前,我们应该实现一些目标。 您将需要正确的工具来构建和部署应用程序,还需要正确的API(使您能够使用平台及其所有功能的API)。

Microsoft has been doing a lot of good work in this area. Yes, Windows Azure is a Windows-based platform that seems to target only .NET languages. However, when you look at the tools, tutorials, APIs, and blog posts around PHP and Windows Azure, it is clear that PHP is an equally valued citizen of the platform!

微软在这方面做得很好。 是的,Windows Azure是一个基于Windows的平台,似乎只针对.NET语言。 但是,当您查看有关PHP和Windows Azure的工具,教程,API和博客文章时,很明显PHP是该平台的同等价值公民!

Let’s take a tour of all the tools and APIs that are available for PHP on Windows Azure today. A lot of these tools are very easy to install using the Web Platform Installer—a “check-next-finish” wizard that allows you to install platforms and tools in an easy and efficient manner.

让我们浏览一下当今Windows Azure上可用于PHP的所有工具和API。 使用Web Platform Installer可以很容易地安装许多工具,这是一个“检查-下一步完成”向导,可让您以简单有效的方式安装平台和工具。

IDE支持 (IDE Support)

Of course, you can use your favorite editor to work on a PHP application that’ll be hosted on Windows Azure. On the other hand, if you’re using an Eclipse-based editor like Eclipse PDT, Zend Studio, or Aptana, you can take advantage of a great plugin that will speed up your development efforts, shown in Figure 2, “Using Eclipse for development”.

当然,您可以使用自己喜欢的编辑器来处理将在Windows Azure上托管PHP应用程序。 另一方面,如果您使用的是基于Eclipse的编辑器(例如Eclipse PDT,Zend Studio或Aptana),则可以利用功能强大的插件来加快开发工作,如图2所示,“将Eclipse用于发展”。

The Eclipse plugin for Windows Azure is available at http://windowsazure4e.org. Also, Josh Holmes has prepared a handy post, Easy Setup for PHP on Azure Development.

Windows Azure的Eclipse插件可从http://windowsazure4e.org获得 。 另外,Josh Holmes还准备了一个方便的帖子, 《 Azure开发上PHP轻松安装》 。

Using Eclipse for development

使用Eclipse进行开发

After installing the plugin, you’ll find the following features have been added to your IDE:

安装插件后,您会发现以下功能已添加到您的IDE中:

  • Project Creation and Migration allows for the easy migration

    通过项目创建和迁移,可以轻松进行迁移

    of an existing application to a Windows Azure application. This

    现有应用程序迁移到Windows Azure应用程序。 这个

    tool will get your application ready for packaging and deployment

    工具将使您的应用程序准备好进行打包和部署

    to Windows Azure.

    Windows Azure。

  • Storage Explorer provides access to your Windows Azure

    Storage Explorer提供对Windows Azure的访问

    storage accounts and allows you to upload and download blobs,

    存储帐户,并允许您上传和下载Blob,

    query tables, list queues, and so on.

    查询表,列表队列等。

  • Debugging and local testing is also included: there’s no

    调试和本地测试也包括在内:

    need to deploy and test your application immediately on Windows

    需要立即在Windows上部署和测试您的应用程序

    Azure. A “local cloud” simulation environment is available.

    Azure。 可以使用“本地云”模拟环境。

打包 (Packaging)

Once your application is ready for deployment, it should be packaged for Windows Azure. Packaging is basically the process of creating a ZIP archive of your application and embedding a manifest of all the included files and their configuration requirements.

准备好要部署的应用程序后,应将其打包为Windows Azure。 打包基本上是创建应用程序的ZIP存档并嵌入所有包含的文件及其配置要求的清单的过程。

The Eclipse plugin for Windows Azure contains this feature. However, if you don’t use Eclipse as your IDE, or if you’re working in a non-Windows environment, you can package your application using the Windows Azure command-line tools for PHP developers.

Windows Azure的Eclipse插件包含此功能。 但是,如果您不使用Eclipse作为IDE,或者在非Windows环境中工作,则可以使用适用于PHP开发人员的Windows Azure命令行工具打包应用程序。

开发工具和SDK (Development Tools and SDKs)

Next, let’s take a spin around some of the tools and SDKs that Windows Azure makes available to developers.

接下来,让我们来看看Windows Azure提供给开发人员的一些工具和SDK。

适用于PHP的Windows Azure SDK (Windows Azure SDK for PHP)

If you’re planning on migrating an application or building a new one for Windows Azure, chances are that you’ll need storage. This is where the Windows Azure SDK for PHP comes in handy: it gives you easy access to the blob storage, table storage and queue services provided by Windows Azure. You can download this SDK as a stand-alone, open-source package that allows you to access storage from both on-premises locations and your cloud application. If you’re using the Eclipse plug-in we discussed earlier, you’ll find this API is included.

如果您打算迁移应用程序或为Windows Azure构建新的应用程序,则很可能需要存储。 这是用于PHP的Windows Azure SDK派上用场的地方:它使您可以轻松访问Windows Azure提供的Blob存储,表存储和队列服务。 您可以将此SDK作为独立的开源程序包下载,该程序包使您可以从本地位置和云应用程序访问存储。 如果您使用的是我们前面讨论的Eclipse插件,则会发现此API包含在内。

The process of utilizing storage always starts with setting up your credentials: an account name and a shared key (think of this as a very long password). Then, you can use one of the specific classes available for blob storage, table storage, or queue storage.

利用存储空间的过程总是从设置凭据开始:一个帐户名和一个共享密钥(将其视为一个很长的密码)。 然后,您可以使用可用于Blob存储,表存储或队列存储的特定类之一。

Here’s an example of blob storage in action. First, I create a container (think of this as a virtual hard drive). Then, I upload a file from my local hard drive to blob storage:

这是一个实际的Blob存储示例。 首先,我创建一个容器(将其视为虚拟硬盘驱动器)。 然后,我将文件从本地硬盘驱动器上传到Blob存储:

/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';
$storageClient = new Microsoft_WindowsAzure_Storage_Blob();
$storageClient->createContainer('testcontainer');
// upload /home/maarten/example.txt to Windows Azure
$result = $storageClient->putBlob('testcontainer', 'example.txt', '/home/maarten/example.txt');

Reading the blob afterwards is fairly straightforward:

之后读取blob非常简单:

/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';
$storageClient = new Microsoft_WindowsAzure_Storage_Blob();
// download file to /home/maarten/example.txt
$storageClient->getBlob('testcontainer', 'example.txt', '/home/maarten/example.txt');

Table storage is a bit more complex. It’s like a very scalable database that’s not bound to a schema, and has limited querying possibilities. To use table storage, you’ll require some classes that can be used both by your PHP application and Windows Azure table storage. Here’s an example class representing a person:

表存储有点复杂。 它就像一个非常可伸缩的数据库,没有绑定到架构,并且查询的可能性有限。 若要使用表存储,您将需要一些可以由PHP应用程序和Windows Azure表存储使用的类。 这是一个代表人的示例类:

class Person extends Microsoft_WindowsAzure_Storage_TableEntity
{
/**
* @azure Name
*/
public $Name;
/**
* @azure Age Edm.Int64
*/
public $Age;
}

Inserting an instance of Person into the table is as easy as creating a new instance and assigning it some properties. After that, the table storage API in the Windows Azure SDK for PHP allows you to insert the entity into a table namedtesttable:

Person实例插入表中就像创建一个新实例并为其分配一些属性一样容易。 之后,用于PHP的Windows Azure SDK中的表存储API允许您将实体插入名为testtable的表中:

/** Microsoft_WindowsAzure_Storage_Table */
require_once 'Microsoft/WindowsAzure/Storage/Table.php';
$entity = new Person('partition1', 'row1');
$entity->Name = "Maarten";
$entity->Age = 25;
$storageClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', 'myaccount', 'myauthkey');
$storageClient->insertEntity('testtable', $entity);

That was a lot of information in one code snippet! First of all, what are partition1 and row1? Well, those are the partition key and row key. The partition key is a logical grouping of entities. In an application where users can contribute blog posts, for example, a good candidate for the partition key would be the username—this would allow you to easily query for all data related to a given user. The row key is the unique identifier for the row.

一个代码段中包含了很多信息! 首先, partition1和row1是什么? 好吧,这些是分区键和行键。 分区键是实体的逻辑分组。 例如,在用户可以发表博客帖子的应用程序中,分区键的最佳选择就是用户名-这将使您轻松查询与给定用户相关的所有数据。 行键是该的唯一标识符。

Queues follow the same idea—there’s an API that allows you to put, get, and delete messages from the queue on Windows Azure. Queues are also guaranteed to be processed: when a message is read from the queue, data is made invisible for a specific time. If, after that time, the message has not been explicitly removed, for example because a batch script has crashed, the message will re-appear and be available for processing again.

队列遵循相同的想法-有一个API,您可以通过它在Windows Azure上从队列中放入,获取和删除消息。 还保证队列得到处理:从队列中读取消息时,数据在特定时间内不可见。 如果在那之后,仍未明确删除该消息,例如由于批处理脚本崩溃,则该消息将重新出现并可以再次处理。

The Windows Azure SDK for PHP also has some extra features that are specific to both PHP and Windows Azure. This includes features like a session storage provider that allows you to share web session data over multiple web role instances. Another feature is a stream wrapper that allows you to use standard file functions like fopen on blob storage.

用于PHP的Windows Azure SDK还具有一些特定于PHP和Windows Azure的额外功能。 这包括会话存储提供程序之类的功能,该功能使您可以在多个Web角色实例上共享Web会话数据。 流包装器的另一个功能是允许您在blob存储上使用标准文件功能(例如fopen

An example application, ImageCloud, which uses all the features described above, is available for download on my blog.

使用上述所有功能的示例应用程序ImageCloud可在我的博客上下载。

适用于PHPSQL Server驱动程序 (SQL Server Driver for PHP)

The SQL Server Driver for PHP allows PHP developers to access SQL Server databases that are hosted on SQL Server or SQL Azure. The SQL Server Driver for PHP relies on the Microsoft SQL Server ODBC Driver to handle low-level communication with SQL Server. As a result, the SQL Server Driver for PHP is only supported on Windows and Windows Azure. It can be downloaded and installed as a PHP extension.

PHPSQL Server驱动程序允许PHP开发人员访问SQL Server或SQL Azure上托管SQL Server数据库。 用于PHPSQL Server驱动程序依赖于Microsoft SQL Server ODBC驱动程序来处理与SQL Server的低级通信。 因此,仅Windows和Windows Azure支持PHPSQL Server驱动程序。 可以下载并作为PHP扩展安装。

When you download this driver, be sure to download version 2.0. This version has the additional benefit that it provides PDO (PHP Data Objects) support, which allows you to quickly switch between, for example, MySQL and SQL Server.

当您下载此驱动程序时,请确保下载版本2.0。 此版本的另一个好处是,它提供了PDO(PHP数据对象)支持,使您可以在例如MySQL和SQL Server之间快速切换。

Now, let’s imagine you have an SQL Azure database. The following code shows how you can connect to the blog database on your SQL Azure database server and retrieve the posts ordered by publication date:

现在,让我们假设您有一个SQL Azure数据库。 以下代码显示如何连接到SQL Azure数据库服务器上的blog数据库并检索按发布日期排序的帖子:

// Connect to SQL Azure using PDO
$connection = new PDO('bvoj6aovnk.database.windows.net', 'sqladm@bvoj6aovnk', 'mypassword', array('Database' => 'blog'));
// Fetch specific post
$posts = array();
$query = 'SELECT * FROM posts ORDER BY PubDate DESC';
$statement = $connection->query($query);
while ( $row = $statement->fetchObject('Post') ) {
$posts[] = $row;
}

适用于PHP的AppFabric SDK (AppFabric SDK for PHP)

As I mentioned before, the Windows Azure Platform AppFabric (not to be confused with the Windows Server AppFabric) enables you to delegate user authentication and authorization, and to punch firewalls and connect applications across different protected networks with ease. You can download it from http://dotnetservicesphp.codeplex.com.

如前所述,Windows Azure Platform AppFabric(不要与Windows Server AppFabric混淆)使您可以委派用户身份验证和授权,并轻松打通防火墙并跨不同的受保护网络连接应用程序。 您可以从http://dotnetservicesphp.codeplex.com下载。

In terms of authentication and authorization, it’s important to know a little about claims-based authentication and federation—a topic on which some interesting resources are available. Basically, your application establishes a trust relationship with an authentication authority (like Windows Azure Platform AppFabric), which means that your application trusts users that are authenticated with that authority. Next, your application will ask its users to claim their rights. For example, my application could ask the user to claim that they can create orders:

在身份验证和授权方面,重要的一点是要了解基于声明的身份验证和联合身份,这是一个可以获取一些有趣资源的主题。 基本上,您的应用程序与身份验证机构(例如Windows Azure Platform AppFabric)建立信任关系,这意味着您的应用程序信任使用该身份验证的用户。 接下来,您的应用程序将要求其用户声明其权利。 例如,我的应用程序可以要求用户声明可以创建订单:

$requiredClaims = array('CreateOrder' => true);
if (ValidateClaimUtil::ValidateClaims($requiredClaims, "phpservice", 'http://localhost/SalesDashboard/', $signingKey))
{
// User is allowed to create an order!
}
else
{
// User is not authorized.
}

The Windows Azure Platform AppFabric Access Control Service will validate that the user has this claim, and sign a security token with that information. Since your application trusts this authority, it will either continue or fail on the basis of whether or not the claim is valid.

Windows Azure平台AppFabric访问控制服务将验证用户是否拥有此声明,并使用该信息签名安全令牌。 由于您的应用程序信任此权限,因此它将根据声明是否有效来继续执行或失败。

Now magine having two applications that cannot connect to each other because of firewall-related policies. If both applications can establish an outgoing connection to the service bus, the service bus will relay communication between the two applications. It’s as easy as that—and incredibly useful if you have a tough IT department!

现在想象一下,有两个应用程序由于与防火墙相关的策略而无法相互连接。 如果两个应用程序都可以建立到服务总线的传出连接,则服务总线将中继两个应用程序之间的通信。 就这么简单-如果您的IT部门很艰巨,那就非常有用!

The benefits of Windows Azure Platform AppFabric Service Bus

Windows Azure平台AppFabric Service Bus的好处

Showing you example code of how this works would lead us too far (since it would involve some configuration and set up tasks). But if you think this sounds like a great feature, check the AppFabric for PHP website, which contains plenty of tutorials on this matter.

向您显示此工作方式的示例代码会使我们走得太远(因为它将涉及一些配置和设置任务)。 但是,如果您认为这听起来像是一个很棒的功能,请访问AppFabric for PHP网站 ,其中包含有关此问题的大量教程。

其他特性 (Other Features)

In addition all the features and APIs we’ve already investigated, there are a number of other features and products that are worth looking at. These features aren’t always Windows Azure-specific, like the URL rewriting module for IIS7, but your application can benefit greatly from them all the same.

除了我们已经研究过的所有功能和API外,还有许多其他功能和产品值得研究。 这些功能并不总是特定于Windows Azure的,例如IIS7的URL重写模块,但是您的应用程序可以从中受益匪浅。

PHP Azure贡献 (PHP Azure Contributions)

The Windows Azure platform provides some useful features, like reading configuration files (which can be modified even after a deployment has been done), or logging into the Windows Azure environment and accessing local storage on a virtual machine to store files temporarily. Unfortunately, these features are baked in to the Windows Azure Cloud Guest OS, and not available as REST services.

Windows Azure平台提供了一些有用的功能,例如读取配置文件(即使在完成部署后也可以修改),或登录Windows Azure环境并访问虚拟机上的本地存储以临时存储文件。 不幸的是,这些功能已嵌入Windows Azure Cloud Guest OS中,不能作为REST服务使用。

Luckily however, these features are exposed as a C dynamic link library, which means that writing a PHP extension to interface with them is a logical step. And that’s exactly what the PHP Azure Contributions library provides: a PHP extension to make use of configuration data, logging, and local storage. Imagine having a configuration value named EmailSubject in your ServiceConfiguration.csdef file. Reading this value is very easy using the PHP Azure Contributions extension:

但是幸运的是,这些功能作为C动态链接库公开,这意味着编写PHP扩展以与它们进行接口是一个逻辑步骤。 这正是PHP Azure贡献库提供的功能:一个PHP扩展,用于使用配置数据,日志记录和本地存储。 想象一下,在ServiceConfiguration.csdef文件中有一个名为EmailSubject的配置值。 使用PHP Azure贡献扩展,读取此值非常容易:

$$emailSubject = azure_getconfig("EmailSubject");

We can also write data to the Windows Azure diagnostics log. Here’s an example in which I’m writing an informational message in the diagnostics log:

我们还可以将数据写入Windows Azure诊断日志。 这是一个示例,其中我在诊断日志中写了一条参考消息:

azure_log("This is some useful information!", "Information");

The PHP Azure Contributions project is available on CodePlex athttp://phpazurecontrib.codeplex.com.

可通过CodePlex的http://phpazurecontrib.codeplex.com获得PHP Azure贡献项目。

URL重写 (URL Rewriting)

As a PHP developer, you may already use URL rewriting. In Apache’s .htaccess files, it’s very easy to enable the rewrite engine, and to rewrite incoming URLs to real scripts. For example, the URL http://www.example.com/products/books may be mapped tohttp://www.example.com/index.php?page=products&category=books on your server. This technique is also available in IIS7, the Microsoft web server that’s also used in Windows Azure web roles. The above URL rewriting example can be defined in theWeb.config file in the root of your Windows Azure application:

作为PHP开发人员,您可能已经在使用URL重写。 在Apache的.htaccess文件中,启用重写引擎并将传入的URL重写为真实脚本非常容易。 例如,URL http://www.example.com/products/books可能映射到服务器上的http://www.example.com/index.php?page=products&category=books 。 IIS7中也可以使用此技术,IIS 7是Windows Azure Web角色中也使用的Microsoft Web服务器。 可以在Windows Azure应用程序根目录中的Web.config文件中定义以上URL重写示例:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteProductsUrl" enabled="true" stopProcessing="true">
<match url="^products/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?page=products&category={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Also note that, because your application is hosted on an IIS web server in Windows Azure, you can use any HttpModule for IIS, just as you would for a traditionally hosted application. This makes it easy to enable output compression, leverage the IIS authentication and authorization features, and more. Download the IIS URL Rewrite module from http://www.iis.net/download/urlrewrite.

还要注意,由于您的应用程序托管在Windows Azure中的IIS Web服务器上,因此您可以对IIS使用任何HttpModule,就像对传统托管的应用程序一样。 这使得启用输出压缩,利用IIS身份验证和授权功能以及其他功能变得容易。 从http://www.iis.net/download/urlrewrite下载IIS URL重写模块。

WinCache扩展 (WinCache Extension)

As you may know, PHP files are interpreted into bytecode and executed from that bytecode on every request. This process is quite fast, but on high-traffic websites, it’s recommended that we cache the bytecode and skip script interpretation. This technique increases a website’s performance without requiring additional resources.

您可能知道,PHP文件被解释为字节码,并在每次请求时从该字节码执行。 这个过程相当快,但是在人流量大的网站上,建议我们缓存字节码并跳过脚本解释。 此技术无需其他资源即可提高网站的性能。

On Linux, accelerator modules that utilize these techniques, like APC and IonCube, are very common. These also work on Windows and could potentially also work on Windows Azure. However, Microsoft also released its own module that applies this technique: the WinCache extension for PHP. This extension is the fastest PHP accelerator on Windows, and also provides features like storing session data in this cache layer. The Wincache extension for PHP can be downloaded from http://www.iis.net/download/wincacheforphp.

在Linux上,利用这些技术的加速器模块(例如APC和IonCube)非常常见。 这些也可以在Windows上运行,并且还可能在Windows Azure上运行。 但是,Microsoft还发布了自己的应用此技术的模块:WinCache PHP扩展。 该扩展是Windows上最快PHP加速器,还提供了一些功能,例如在此缓存层中存储会话数据。 可以从http://www.iis.net/download/wincacheforphp下载适用于PHP的Wincache扩展。

CDN –内容交付网络 (CDN – Content Delivery Network)

When using Windows Azure blob storage, you’ll find that a full-featured content delivery network (CDN) is available as well. A CDN ensures that, for example, when a user downloads an image, that image will be retrieved from a storage server that’s close to that user’s client. This ensures that the download speed and latency are optimal, and the user receives the image very quickly.

使用Windows Azure Blob存储时,您会发现还提供功能齐全的内容交付网络(CDN)。 CDN确保例如当用户下载图像时,将从与该用户客户端接近的存储服务器中检索该图像。 这样可以确保最佳的下载速度和延迟,并且用户可以非常快速地接收图像。

With blob storage, enabling the CDN is as easy as clicking a button. After that, your public containers are replicated to the CDN, which allows your site’s users to retrieve files and resources as swiftly as possible!

使用blob存储,启用CDN就像单击按钮一样简单。 之后,将您的公共容器复制到CDN,这使您站点的用户可以尽快检索文件和资源!

Using the Windows Azure CDN

使用Windows Azure CDN

域名映射 (Domain Name Mapping)

With Windows Azure, your application will be assigned a domain name under the cloudapp.net domain—for example, myphpapp.cloudapp.net. I think you’ll agree that this isn’t the greatest URL. It gets even worse when you’re using blob storage for hosting files: myphpappstorage.blob.core.windows.net is, well, just plain ugly!

使用Windows Azure,将为您的应用程序分配cloudapp.net域下的域名,例如myphpapp.cloudapp.net 。 我想您会同意这不是最大的URL。 当您使用Blob存储托管文件时,情况变得更糟: myphpappstorage.blob.core.windows.net真是丑陋!

Luckily, all URLs in Windows Azure can be mapped a custom domain name. So, to map www.myphpapp.com to myphpapp.cloudapp.net, you just need to add a CNAME record to your name server. The same applies to blob storage:storage.myphpapp.com can be mapped to the very long myphpappstorage.blob.core.windows.net through the addition of a CNAME record to your DNS server.

幸运的是,可以将Windows Azure中的所有URL映射为自定义域名。 因此,要将www.myphpapp.com映射到myphpapp.cloudapp.net ,只需要将CNAME记录添加到名称服务器中。 这同样适用于blob存储:通过向DNS服务器添加CNAME记录,可以将storage.myphpapp.com映射到很长的myphpappstorage.blob.core.windows.net

Check Azure team member Steve Marx’s post on custom domain names for more on this.

有关更多信息,请查看Azure团队成员Steve Marx关于自定义域名的文章 。

结论 (Conclusion)

In this article, we’ve taken a snapshot of the Windows Azure platform from a PHP perspective. While I’m slightly biased by having contributed to the Windows Azure SDK for PHP, I do think that the Windows Azure platform is a great choice for hosting PHP applications in a highly-scalable cloud environment. I also feel that there’s great value to be found in features like the Windows Azure AppFabric Service Bus. The bottom line is: I believe that Microsoft is doing their best in making PHP a first-class citizen on their cloud platform.

在本文中,我们从PHP的角度拍摄了Windows Azure平台的快照。 尽管我为Windows Azure SDK for PHP做出了一些贡献,但我确实认为Windows Azure平台是在高度可扩展的云环境中托管PHP应用程序的绝佳选择。 我还觉得在Windows Azure AppFabric Service Bus等功能中可以找到很大的价值。 底线是:我相信微软正在尽最大努力使PHP成为其云平台上的一流公民。

Another great resource related to PHP and Windows Azure is http://www.interoperabilitybridges.com, the website that lists all PHP and open-source projects from Microsoft.

与PHP和Windows Azure有关的另一个重要资源是http://www.interoperabilitybridges.com ,该网站列出了Microsoft的所有PHP和开源项目。

note: Microsoft: A SitePoint Business Partner This article has been made possible with the support of Microsoft. We work closely with Microsoft to help develop the content that’s most useful and relevant to you—our readers.

注意: Microsoft:SitePoint业务合作伙伴在Microsoft的支持下,使本文成为可能。 我们与Microsoft紧密合作,以帮助开发最有用且与您(我们的读者)相关的内容。

翻译自: https://www.sitepoint.com/host-php-in-the-cloud-with-windows-azure/

最后

以上就是柔弱香水为你收集整理的使用Windows Azure在云中托管PHP的全部内容,希望文章能够帮你解决使用Windows Azure在云中托管PHP所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部