Installation guide
'validation' => false
));
Cache instance profile credentials
When you do not provide credentials to the SDK and do not have credentials defined in your environment variables,
the SDK will attempt to utilize IAM instance profile credentials by contacting the Amazon EC2 instance metadata
service (IMDS). Contacting the IMDS requires an HTTP request to retrieve credentials from the IMDS.
You can cache these instance profile credentials in memory until they expire and avoid the cost of sending an HTTP
request to the IMDS each time the SDK is utilized. Set the credentials.cache option to true to attempt to
utilize the Doctrine Cache PHP library to cache credentials with APC.
$client = Aws\DynamoDb\DynamoDbClient::factory(array(
'region' => 'us-west-2',
'credentials.cache' => true
));
Note
You will need to install Doctrine Cache in order for the SDK to cache credentials when setting
credentials.cache to true. You can add doctrine/cache to your composer.json dependencies by adding to
your project's required section:
{
"required": {
"aws/sdk": "2.*",
"doctrine/cache": "1.*"
}
}
Check if you are being throttled
You can check to see if you are being throttled by enabling the exponential backoff logger option. You can set the
client.backoff.logger option to debug when in development, but we recommend that you provide a
Guzzle\Log\LogAdapterInterface object when running in production.
$client = Aws\DynamoDb\DynamoDbClient::factory(array(
'region' => 'us-west-2',
'client.backoff.logger' => 'debug'
));
When using Amazon DynamoDB, you can monitor your tables for throttling using Amazon CloudWatch.
Preload frequently included files
The AWS SDK for PHP adheres to PSR-0 and heavily utilizes class autoloading. Each class is in a separate file and
are included lazily as they are required. Enabling an opcode cache like APC, setting apc.stat=0, and utilizing an
optimized Composer autoloader will help to mitigate the performance cost of autoloading the classes needed to
utilize the SDK. In situations like hosting a webpage where you are loading the same classes over and over, you can
shave off a bit more time by compiling all of the autoloaded classes into a single file thereby completely eliminating
the cost of autoloading. This technique can not only speed up the use of the SDK for specific use cases (e.g. using
the Amazon DynamoDB session handler), but can also speed up other aspects of your application. Even with
apc.stat=0, preloading classes that you know will be used in your application will be slightly faster than relying on
autoloading.
You can easily generate a compiled autoloader file using the ClassPreloader project. View the project's README for
information on creating a "preloader" for use with the AWS SDK for PHP.
Performance Guide
45