A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to query the information about a bucket.

The following code provides an example on how to query the information about a bucket:

<? 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\OssClient;
use OSS\Core\OssException;

// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
$accessKeyId = "<yourAccessKeyId>";
$accessKeySecret = "<yourAccessKeySecret>";
// The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
$bucket= "<yourBucketName>";

$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);

try {
    // Query the information about the bucket, including the bucket name, region, created time, storage class, public endpoint, and internal endpoint.
    $info = $ossClient->getBucketInfo($bucket);    
    printf("bucket name:%s\n", $info->getName());    
    printf("bucket location:%s\n", $info->getLocation());    
    printf("bucket creation time:%s\n", $info->getCreateDate());    
    printf("bucket storage class:%s\n", $info->getStorageClass());   
    printf("bucket extranet endpoint:%s\n", $info->getExtranetEndpoint());    
    printf("bucket intranet endpoint:%s\n", $info->getIntranetEndpoint());
} catch (OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}

print(__FUNCTION__ . ": OK" . "\n");

For more information about how to query information about a bucket, see GetBucketInfo.