[英]Php - Amazon s3 how do I check my connection is success or not
I am using amazon-php-sdk. 我正在使用amazon-php-sdk。 In my application I'm accepting key and secret value from a form and passing for connecting to Aws.
在我的应用程序中,我接受表单中的密钥和秘密值,并通过连接到Aws。 Here is my code.
这是我的代码。
<?php
require 'aws-autoloader.php';
use Aws\S3\S3Client;
try {
$s3Client = S3Client::factory(array(
'key' => 'my key',
'secret' => 'my secret key'
));
}
catch(S3Exception $e) {
echo 'Msg' . $e->getMessage();
}
?>
As Michael pointed out, you have to make an actual request to check the connection.AWS discourages any unnecessary validation requests which will affect the performance of your application and your usage bill. 正如Michael指出的那样,您必须提出检查连接的实际请求.AWS不鼓励任何不必要的验证请求,这些请求会影响您的应用程序和使用账单的性能。
But if you need to validate you can use ListBucket or HEAD request on a bucket. 但是如果需要验证,可以在存储桶上使用ListBucket或HEAD请求。
Checkout this best practises article . 查看此最佳实践文章 。
require 'vendor/autoload.php';
use Aws\S3\S3Client;
try {
// Instantiate the S3 client with your AWS credentials
$s3Client = S3Client::factory(array(
'credentials' => array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
)
));
$buckets = $s3Client->listBuckets();
}
catch(Exception $e) {
exit($e->getMessage());
}
To answer your second question.You can use doesObjectExist function which returns a boolean . 回答你的第二个问题。你可以使用返回布尔值的 doesObjectExist函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.