Creating and Configuring an OBS Client
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see API Reference.
Scenarios
This section describes how to create and configure an OBS client.
Prerequisites
Ensure you have completed the following preparations:
- Select a proper SDK version by referring to Before You Start.
- Prepare the service and development environments by referring to Preparations.
- Download and install the OBS SDK for PHP by referring to Downloading and Installing the SDK.
Configuring Parameters
|
Parameter |
Description |
Recommended Value |
|---|---|---|
|
key |
AK |
N/A |
|
secret |
SK |
N/A |
|
endpoint |
Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port name. For example, https://your-endpoint:443. For security purposes, you are advised to use HTTPS. |
N/A |
|
ssl_verify |
Whether to verify server-side certificates. Possible values are:
The default value is false. |
N/A |
|
max_retry_count |
Maximum number of retries when an HTTP/HTTPS connection is abnormal. The default value is 3. |
[1, 5] |
|
socket_timeout |
Timeout duration for transmitting data at the socket layer, in seconds. The default value is 60. |
[10, 60] |
|
connect_timeout |
Timeout period for establishing an HTTP/HTTPS connection, in seconds. The default value is 60. |
[10, 60] |
|
chunk_size |
Block size for reading socket streams, in bytes. The default value is 65536. |
Default value |
|
is_cname |
Whether to use a user-defined domain name to access OBS. The default value is false.
NOTE:
To protect your services from being affected by the takeover of Huawei Cloud public domain names by relevant organizations, you are advised to use a user-defined domain name to access a bucket. |
N/A |
- Parameters whose recommended value is N/A need to be set according to the actual conditions.
- If the network is unstable, you are advised to set larger values for socket_timeout and connect_timeout.
- If the endpoint you specified does not contain a protocol, HTTPS is used by default.
By Using the Constructor
// 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. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. // 'security_token' => getenv('SECURITY_TOKEN'), 'endpoint' => 'https://your-endpoint', ]); // Use the instance to access OBS. // Close obsClient. $obsClient -> close();
By Using the Factory Method
// Declare the namespace. use Obs\ObsClient; // Create an instance of ObsClient. $obsClient = ObsClient::factory ( [ //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. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. // 'security_token' => getenv('SECURITY_TOKEN'), 'endpoint' => 'https://your-endpoint', ]); // Use the instance to access OBS. // Close obsClient. $obsClient -> close();
- The project can contain one or more instances of ObsClient.
- After you call the ObsClient -> close method to close an instance of ObsClient, the instance cannot be used any more.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.