All Products
Search
Document Center

Object Storage Service:Transfer acceleration (PHP SDK V2)

Last Updated:Mar 20, 2026

Transfer acceleration improves the speed of OSS access for users across the world. It is suited for long-distance data transmission and uploading or downloading large files that are gigabytes or terabytes in size.

Prerequisites

Before you begin, ensure that you have:

  • An OSS bucket

  • The Alibaba Cloud PHP SDK V2 installed (AlibabaCloud\Oss\V2)

  • Your AccessKey ID and AccessKey secret set as environment variables

Enable transfer acceleration

Call putBucketTransferAcceleration with enabled: true to turn on transfer acceleration for a bucket.

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Load credentials from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider);
$cfg->setRegion('<region-id>');          // e.g., cn-hangzhou
// $cfg->setEndpoint('<endpoint>');      // Optional: set a custom endpoint

$client = new Oss\Client($cfg);

$request = new Oss\Models\PutBucketTransferAccelerationRequest(
    bucket: '<bucket-name>',
    transferAccelerationConfiguration: new Oss\Models\TransferAccelerationConfiguration(
        enabled: true
    )
);

$result = $client->putBucketTransferAcceleration($request);

printf(
    'status code: %s' . PHP_EOL .
    'request ID: %s' . PHP_EOL,
    $result->statusCode,
    $result->requestId
);

Replace the following placeholders with actual values:

PlaceholderDescriptionExample
<region-id>The region where the bucket is locatedcn-hangzhou
<bucket-name>The name of the bucketexamplebucket

Query transfer acceleration status

Call getBucketTransferAcceleration to check whether transfer acceleration is currently enabled for a bucket.

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Load credentials from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider);
$cfg->setRegion('<region-id>');          // e.g., cn-hangzhou
// $cfg->setEndpoint('<endpoint>');      // Optional: set a custom endpoint

$client = new Oss\Client($cfg);

$request = new Oss\Models\GetBucketTransferAccelerationRequest(
    bucket: '<bucket-name>'
);

$result = $client->getBucketTransferAcceleration($request);

printf(
    'status code: %s' . PHP_EOL .
    'request ID: %s' . PHP_EOL .
    'transfer acceleration enabled: %s' . PHP_EOL,
    $result->statusCode,
    $result->requestId,
    var_export($result->transferAccelerationConfiguration->enabled, true)
);

Usage notes

  • The sample code uses the China (Hangzhou) region (cn-hangzhou) as an example. Replace this with your actual region. For supported regions and their endpoints, see Regions and endpoints.

  • By default, the SDK uses the public endpoint. To access OSS from another Alibaba Cloud service in the same region, set $cfg->setEndpoint() to the internal endpoint for that region.

What's next