The OTSClient is the client for Table Store. It provides a series of methods for callers to perform operations on tables and read data from or write data to a single row or multiple rows. To use the PHP SDK to initiate a request to Table Store, you need to initialize an OTSClient instance and modify the default configurations of OTSClientConfig as required.

  • You can access a Table Store instance over the Internet or intranet.
  • You can log on to the Table Store console and go to the instance details page. The instance access URL on the page is the endpoint for that instance.

Determine an endpoint

An endpoint is the domain of a Table Store instance in a region. It supports the formats listed in the following table.

Example Description
http://sun.cn-hangzhou.ots.aliyuncs.com Accesses the sun instance in Hangzhou over the Internet by using the HTTP protocol.
https://sun.cn-hangzhou.ots.aliyuncs.com Accesses the sun instance in Hangzhou over the Internet by using the HTTPS protocol.
Note
  • You can access a Table Store instance over the Internet or intranet.
  • You can log on to the Table Store console and go to the instance details page. The instance access URL on the page is the endpoint for that instance.

Configure an AccessKey

To access Table Store, you must have a valid AccessKey for signature authentication. The following types of AccessKeys are supported:

  • To obtain the AccessKey ID and AccessKey Secret of the Alibaba Cloud account, follow these steps:

    1. Register an Alibaba Cloud account on the Alibaba Cloud website.
    2. Log on to the Alibaba Cloud console and apply for an AccessKey.
  • To obtain the AccessKey ID and AccessKey Secret of a RAM user authorized to access Table Store, follow these steps:

    1. Use your Alibaba Cloud account to access RAM and create a RAM user or use an existing one.
    2. Use your Alibaba Cloud account to authorize the RAM user to access Table Store.
    3. After authorization, the AccessKey ID and AccessKey Secret of the RAM user can be used to access Table Store.
  • To obtain an STS token for temporary access, follow these steps:

    1. Obtain the temporary AccessKey ID, AccessKey Secret, and token from the application server, which accesses RAM or STS to obtain the preceding information.
    2. Use the received AccessKey ID, AccessKey Secret, and token to access Table Store.

Initialize an OTSClient instance

After obtaining the AccessKey ID and AccessKey Secret, initialize an OTSClient instance.

  1. Use the endpoint of Table Store to create a client. An example is as follows:
        $otsClient = new OTSClient(array(
            'EndPoint' => "<your endpoint>",
            'AccessKeyID' => "<your access id>",
            'AccessKeySecret' => "<your access key>"
            'InstanceName' => "<your instance name>"
        ));
    

    Note:

    • In addition to the AccessKey ID and AccessKey Secret, the STS token can also be used to access Table Store.

    • When creating an OTSClient instance, you can set parameters such as the timeout time, the maximum number of connections, and the maximum number of retries in OTSClientConfig.

  2. Configure the OTSClient instance.

    To modify the default configuration of the OTSClient instance, import the corresponding parameters, such as the proxy, connection timeout time, and the maximum number of connections, when constructing the OTSClient instance. The following table describes the parameters to be set.

Parameter Description Default value
ConnectionTimeout The maximum latency allowed to connect to Table Store. 2.0 seconds
StsToken The token for temporary access. null
SocketTimeout The maximum latency allowed for the response to each request. 2.0 seconds. We recommend that you set this parameter to a larger value when transmitting a large volume of data.
RetryPolicy The retry policy. DefaultRetryPolicy. If the value is null, the retry feature is disabled.
ErrorLogHandler The error-level log processing function, which is used to display the logs of errors returned by Table Store. defaultOTSErrorLogHandler. If the value is null, this function is disabled.
DebugLogHandler The debug-level log processing function, which is used to display the logs of normal requests and responses. defaultOTSDebugLogHandler. If the value is function, this feature is disabled.

HTTPS

Install the OpenSSL PHP extension.