Help Center/
Object Storage Service/
PHP SDK Developer Guide (Ally Region)/
Lifecycle Management/
Setting Lifecycle Rules
Updated on 2026-01-16 GMT+08:00
Setting Lifecycle Rules
You can call ObsClient->setBucketLifecycle to set lifecycle rules for a bucket.
Setting an Object Transition Policy
Sample code:
// Import the dependency library. require 'vendor/autoload.php'; // Import the SDK code library during source code installation. // require 'obs-autoloader.php'; // Declare the namespace. use Obs\ObsClient; // Create an instance of ObsClient. $obsClient = new ObsClient ( [ //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. //Obtain an AK/SK pair on the management console. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint' ] ); $resp = $obsClient->setBucketLifecycle ( [ 'Bucket' => 'bucketname', 'Rules' => [ [ 'ID' => 'rule1', 'Prefix' => 'prefix1', 'Status' => 'Enabled', 'Transitions' => [ [ 'StorageClass' => ObsClient::StorageClassWarm, 'Days' => 30 ] ], 'NoncurrentVersionTransitions' => [ [ 'StorageClass' => ObsClient::StorageClassCold, 'NoncurrentDays' => 30 ] ] ], [ 'ID' => 'rule2', 'Prefix' => 'prefix2', 'Status' => 'Enabled', 'Transitions' => [ [ 'StorageClass' => ObsClient::StorageClassWarm, 'Date' => '2018-12-31T00:00:00Z' ] ] ] ] ] ); printf ( "RequestId:%s\n", $resp ['RequestId'] );
Setting an Object Expiration Time
Sample code:
// Import the dependency library. require 'vendor/autoload.php'; // Import the SDK code library during source code installation. // require 'obs-autoloader.php'; // Declare the namespace. use Obs\ObsClient; // Create an instance of ObsClient. $obsClient = new ObsClient ( [ //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. //Obtain an AK/SK pair on the management console. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint', ] ); $resp = $obsClient->setBucketLifecycle ( [ 'Bucket' => 'bucketname', 'Rules' => [ [ 'ID' => 'rule1', 'Prefix' => 'prefix1', 'Status' => 'Enabled', // Specify that objects whose names contain the prefix will expire after being created for 60 days. 'Expiration' => [ 'Days' => 60 ], // Specify that objects whose names contain the prefix will expire after becoming noncurrent versions for 60 days. 'NoncurrentVersionExpiration' => [ 'NoncurrentDays' => 60 ] ], [ 'ID' => 'rule2', 'Prefix' => 'prefix2', 'Status' => 'Enabled', // Specify a date when the objects whose name contain the prefix will expire. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time). 'Expiration' => [ 'Date' => '2018-12-31T00:00:00Z' ] ] ] ] ); printf ( "RequestId:%s\n", $resp ['RequestId'] );
Use the Rules parameter to specify the lifecycle rules for a bucket.
Parent topic: Lifecycle Management
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot