• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Bucket Management
  5. Deleting a Bucket

Deleting a Bucket

You can call ObsClient->deleteBucket to delete a bucket. Sample code is as follows:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'

// Delete a bucket.
$resp = $obsClient->deleteBucket([
        'Bucket' => 'bucketname'

printf("RequestId:%s\n", $resp['RequestId']);
  • Only empty buckets (without objects and part fragments) can be deleted.
  • Bucket deletion is a non-idempotence operation and an error will be reported if the to-be-deleted bucket does not exist.