転送アクセラレーション機能により、世界中のユーザーはObject Storage Service (OSS) に保存されているオブジェクトにすばやくアクセスできます。 この機能は、データを長い地理的距離で転送する必要があるシナリオに適用できます。 この機能は、ギガバイトまたはテラバイトのサイズの大きなオブジェクトをダウンロードまたはアップロードするためにも使用できます。
使用上の注意
このトピックでは、中国 (杭州) リージョンのパブリックエンドポイントを使用します。 OSSと同じリージョンにある他のAlibaba CloudサービスからOSSにアクセスする場合は、内部エンドポイントを使用します。 OSSリージョンとエンドポイントの詳細については、「リージョン、エンドポイント、オープンポート」をご参照ください。
このトピックでは、OSSエンドポイントを使用してOSSClientインスタンスを作成します。 カスタムドメイン名またはSecurity Token Service (STS) を使用してOSSClientインスタンスを作成する場合は、「OSSClientインスタンスの作成」をご参照ください。
バケットの転送アクセラレーションを有効にする
次のサンプルコードは、examplebucketという名前のバケットの転送アクセラレーションを有効にする方法の例を示しています。
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "yourEndpoint";
// Specify the name of the bucket. Example: examplebucket.
$bucket= "examplebucket";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
try{
$ossClient->putBucketTransferAcceleration($bucket,true);
printf('putBucketTransferAcceleration SUCCESS' . "\n");
} catch(OssException $e) {
printf($e->getMessage() . "\n");
return;
}
バケットの転送アクセラレーションを有効にするために呼び出すことができるAPI操作の詳細については、「PutBucketTransferAcceleration」をご参照ください。
バケットの転送アクセラレーションステータスの照会
次のサンプルコードは、examplebucketという名前のバケットの転送アクセラレーションステータスを照会する方法の例を示しています。
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "yourEndpoint";
// Specify the name of the bucket. Example: examplebucket.
$bucket= "examplebucket";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
try{
// Query the transfer acceleration status of the bucket.
// If the return value is true, transfer acceleration is enabled for the bucket. If the return value is false, transfer acceleration is disabled for the bucket.
$result = $ossClient->getBucketTransferAcceleration($bucket);
if($result === true){
$status = 'enabled';
}else{
$status = 'disabled';
}
printf('getBucketTransferAcceleration Status:'.$status."\n");
} catch(OssException $e) {
printf($e->getMessage() . "\n");
return;
}
バケットの転送アクセラレーションステータスを照会するために呼び出すことができるAPI操作の詳細については、「GetBucketTransferAcceleration」をご参照ください。