

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 适用于 PHP 的 AWS SDK 版本 3 向 Amazon EventBridge 全球终端节点发送事件
<a name="eventbridge-examples"></a>

您可以使用 [Amazon EventBridge 全球终端节点](https://docs.aws.amazon.com//eventbridge/latest/userguide/eb-global-endpoints.html)来提高事件驱动型应用程序的可用性和可靠性。

[设置 EventBridge ](https://docs.aws.amazon.com//eventbridge/latest/userguide/eb-global-endpoints.html#eb-ge-create-endpoint)全局端点后，您可以使用适用于 PHP 的 SDK 向其发送事件。

**重要**  
要在适用于 PHP 的 SDK 中使用 EventBridge 全局端点，您的 PHP 环境必须安装[AWS 通用运行时 (AWS CRT) 扩展](guide_crt.md)。

以下示例使用的[PutEvents](https://docs.aws.amazon.com//aws-sdk-php/v3/api/api-eventbridge-2015-10-07.html#putevents)方法将单个事件发送`EventBridgeClient`到 EventBridge 全局终端节点。

```
<?php
/* Send a single event to an existing Amazon EventBridge global endpoint. */
require '../vendor/autoload.php';

use Aws\EventBridge\EventBridgeClient;

$evClient = new EventBridgeClient([
    'region' => 'us-east-1'
]);

$endpointId = 'xxxx123456.xxx';  // Existing EventBridge global endpointId.
$eventBusName = 'default';       // Existing event bus in the us-east-1 Region.

$event =  [
    'Source' => 'my-php-app',
    'DetailType' => 'test',
    'Detail' => json_encode(['foo' => 'bar']),
    'Time' => new DateTime(),
    'Resources' => ['php-script'],
    'EventBusName' => $eventBusName,
    'TraceHeader' => 'test'
];

$result = $evClient->putEvents([
    'EndpointId' => $endpointId,
    'Entries' => [$event]
]);
```

[这篇博文](https://aws.amazon.com/blogs//compute/introducing-global-endpoints-for-amazon-eventbridge/)包含有关 EventBridge 全局端点的更多信息。