Help Center> OBS PHP SDK> API Reference> Initialization> ObsClient Initialization
Updated on 2023-11-09 GMT+08:00

ObsClient Initialization

API Description

ObsClient functions as the PHP client for accessing OBS. It offers callers a series of APIs for interaction with OBS. These APIs are used for managing and operating resources, such as buckets and objects, stored in OBS.

Namespace

Class

Parent Namespace

ObsClient

Obs

Method Definition

1. Constructor form: ObsClient(array $parameter)
2. Factory form: ObsClient::factory(array $parameter)

Parameter Description

Field

Type

Optional or Mandatory

Description

key

string

Mandatory

AK

secret

string

Mandatory

SK

endpoint

string

Mandatory

Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port number. For example, https://your-endpoint:443.

To view the endpoints available for OBS, see Regions and Endpoints.

ssl_verify

boolean

or

string

Optional

Whether to verify server-side certificates. Possible values are:

  • Path to the server-side root certificate file in .pem format
  • true: The default CAs are used to verify the server-side certificate.
  • false: The server-side certificates will not be verified.

The default value is false.

max_retry_count

integer

Optional

Maximum number of retries when an HTTP/HTTPS connection is abnormal. The default value is 3.

socket_timeout

integer

Optional

Timeout duration for transmitting data at the socket layer, in seconds. The default value is 60.

connect_timeout

integer

Optional

Timeout period for establishing an HTTP/HTTPS connection, in seconds. The default value is 60.

chunk_size

integer

Optional

Block size for reading socket streams, in bytes. The default value is 65536.

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. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint',
      'ssl_verify' => false,
      'max_retry_count' => 1,
      'socket_timeout' => 20,
      'connect_timeout' => 20,
      'chunk_size' => 8196
]);