The Tablestore client provides a series of methods to manage tables and perform read and write operations on a single row or multiple rows. To use Tablestore SDK for PHP to initiate a request, you must initialize an OTSClient instance and modify the default configurations of OTSClientConfig as needed.

Obtain an endpoint

An endpoint is the domain name that is used to access a Tablestore instance in a region. The following table lists the examples of endpoints.

Example Description
http://sun.cn-hangzhou.ots.aliyuncs.com The public endpoint used to access the sun instance in the China (Hangzhou) region over HTTP.
https://sun.cn-hangzhou.ots.aliyuncs.com The public endpoint used to access the sun instance in the China (Hangzhou) region over HTTPS.
Note
  • Tablestore supports access over the Internet and internal network. For more information, see Endpoint.
  • You can log on to the Tablestore console and go to the Instance Details tab. You can view the endpoints in the Instance Access URL section.

Configure an AccessKey pair

To access Tablestore, you must have an AccessKey pair that consists of an AccessKey ID and AccessKey secret to verify your identity. The following types of AccessKey pairs are supported:

  • The AccessKey pair of an Alibaba Cloud account. To obtain the AccessKey pair of an Alibaba Cloud account, perform the following operations:
    1. Create an Alibaba Cloud account on the Alibaba Cloud official website. For more information, see Create a new Alibaba Cloud account.
    2. Log on to the Alibaba Cloud Management console. Apply for an AccessKey pair. For more information, see Security Management.
  • The AccessKey pair of a RAM user. To obtain the AccessKey pair of an Alibaba Cloud account, perform the following operations:
    1. Use your Alibaba Cloud account to log on to RAM. Create a RAM user or use an existing RAM user.
    2. Use your Alibaba Cloud account to authorize the RAM user to access Tablestore.
    3. After authorization, the AccessKey ID and AccessKey secret of the RAM user can be used to access Tablestore.
  • The AccessKey pair in temporary access credentials. The process of obtaining temporary access credentials is as follows:
    1. The application server uses RAM or STS to obtain access credentials that consist of the temporary AccessKey ID, AccessKey secret, and token. After the access credentials are obtained, the application server sends them to you.
    2. You can use the received access credentials to access Tablestore.

Initialize an OTSClient instance

After you obtain the AccessKey pair, you can perform the following operations to initialize an OTSClient instance:

  1. Use the endpoint of Tablestore to create a client.
    Examples
        $otsClient = new Aliyun\OTS\OTSClient(array(
            'EndPoint' => "<your endpoint>",
            'AccessKeyID' => "<your access id>",
            'AccessKeySecret' => "<your access key>",
            'InstanceName' => "<your instance name>"
        ));
                            
  2. Configure the OTSClient instance.
    To modify the default configurations of the OTSClient instance, import the corresponding parameters such as the proxy, connection timeout time, and the maximum number of connections, when you create the OTSClient instance. The following table lists the parameters you can configure when you create the OTSClient instance.
    Parameter Description Default value
    ConnectionTimeout The maximum latency allowed to connect to Tablestore, in seconds. 2.0
    StsToken The STS token for temporary access. null
    SocketTimeout The maximum latency allowed for the response to each request, in seconds. 2.0. We recommend that you set this parameter to a larger value when large volumes of data are transmitted.
    RetryPolicy The retry policy. DefaultRetryPolicy. A value of null indicates that RetryPolicy is disabled.
    ErrorLogHandler The function to process error logs, which is used to display the logs of errors returned by Tablestore. defaultOTSErrorLogHandler. A value of null indicates that ErrorLogHandler is disabled.
    DebugLogHandler The function to process debug logs, which is used to display the logs of normal requests and responses. defaultOTSDebugLogHandler. A value of null indicates that defaultOTSDebugLogHandler is disabled.

HTTPS

Install the OpenSSL PHP extension.