

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

# 适用于 PHP 的 SDK 中的 `process` 提供程序
<a name="process-provider"></a>

 `Aws\Credentials\CredentialProvider::process`尝试通过执行[共享 AWS 配置文件中配置文件](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html)中指定的`credential_process`值来加载凭证。

默认情况下，SDK 会先尝试从位于的共享 AWS `credentials`文件中加载 “默认” 配置文件`~/.aws/credentials`。如果在共享 `credentials` 文件中找不到“默认”配置文件，SDK 将在共享 `config` 文件中查找默认配置文件。下面是共享 `credentials` 文件的配置示例。

```
[default]
credential_process = /path/to/file/credential_returning_executable.sh --custom-command custom_parameter
```

SDK 将通过使用 PHP 的 `shell_exec` 函数完全调用给定的 `credential_process` 命令，然后从 stdout 中读取 JSON 数据。`credential_process` 必须采用以下格式将凭证写入 stdout：

```
{
    "Version": 1,
    "AccessKeyId": "",
    "SecretAccessKey": "",
    "SessionToken": "",
    "Expiration": ""
}
```

 `SessionToken` 和 `Expiration` 是可选的。如果存在，凭证将被视为临时的。

```
use Aws\Credentials\CredentialProvider;
use Aws\S3\S3Client;

$provider = CredentialProvider::process();
// Cache the results in a memoize function to avoid loading and parsing
// the ini file on every API operation
$provider = CredentialProvider::memoize($provider);

$client = new S3Client([
    'region'      => 'us-west-2',
    'version'     => '2006-03-01',
    'credentials' => $provider
]);
```

您可以通过向创建提供程序的函数提供参数来使用自定义配置文件或 .ini 文件位置。

```
$profile = 'production';
$path = '/full/path/to/credentials.ini';

$provider = CredentialProvider::process($profile, $path);
$provider = CredentialProvider::memoize($provider);

$client = new S3Client([
    'region'      => 'us-west-2',
    'version'     => '2006-03-01',
    'credentials' => $provider
]);
```