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.
||The public endpoint used to access the sun instance in the China (Hangzhou) region over HTTP.|
||The public endpoint used to access the sun instance in the China (Hangzhou) region over HTTPS.|
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:
- The AccessKey pair of a RAM user. To obtain the AccessKey pair of an Alibaba Cloud
account, perform the following operations:
- Use your Alibaba Cloud account to log on to RAM. Create a RAM user or use an existing RAM user.
- Use your Alibaba Cloud account to authorize the RAM user to access Tablestore.
- 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:
- 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.
- 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:
- 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>" ));
- 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.
Install the OpenSSL PHP extension.