PHP AWS SDK创建S3Client时发生致命错误
尝试使用AWS SDK for PHP列出存储桶,但在设置S3客户端后,我一直遇到以下错误:PHP AWS SDK创建S3Client时发生致命错误,php,amazon-web-services,amazon-s3,aws-sdk,aws-php-sdk,Php,Amazon Web Services,Amazon S3,Aws Sdk,Aws Php Sdk,尝试使用AWS SDK for PHP列出存储桶,但在设置S3客户端后,我一直遇到以下错误: <?php require getcwd() . '/aws.phar' /*v3 of the SDK*/; use Aws\S3\S3Client; use Aws\Exception\AwsException; $credentials = new Aws\Credentials\Credentials('I put my', 'credentials here'); $s3 =
<?php
require getcwd() . '/aws.phar' /*v3 of the SDK*/;
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$credentials = new Aws\Credentials\Credentials('I put my', 'credentials here');
$s3 = new Aws\S3\S3Client([
'region' => 'us-east-1', /*also tried different regions*/
'version' => '2006-03-01', /*also tried latest*/
'credentials' => $credentials /*have also tried putting credentials here*/
]);
$s3->listBuckets(); /*still the same error even if I remove this line */ ?>
如果我没有至少填写区域、版本和凭据选项,SDK实际上会返回一个错误,告诉我填写它们。
下面是上面代码返回的错误:
致命错误:未捕获错误:在中调用未定义的函数JmesPath\mb_strlen()phar:///var/www/mail/aws.phar/JmesPath/Lexer.php:343 堆栈跟踪:#0phar:///var/www/mail/aws.phar/JmesPath/Parser.php(76):JmesPath\Lexer->tokenize()#1phar:///var/www/mail/aws.phar/JmesPath/AstRuntime.php(42):JmesPath\Parser->parse() #2 phar:///var/www/mail/aws.phar/JmesPath/Env.php(33):JmesPath\AstRuntime->u invoke()#3phar:///var/www/mail/aws.phar/Aws/Endpoint/PartitionEndpointProvider.php(117):JmesPath\Env::search()#4phar:///var/www/mail/aws.phar/Aws/Endpoint/PartitionEndpointProvider.php(99):Aws\Endpoint\PartitionEndpointProvider::mergePrefixData() #5 phar:///var/www/mail/aws.phar/Aws/ClientResolver.php(740):Aws\Endpoint\PartitionEndpointProvider::defaultProvider()#6phar:///var/www/mail/aws.phar/Aws/ClientResolver.php(295):Aws\ClientResolver::_default_endpoint_provider()#7phar:///var/www/mail/aws.phar/Aws/AwsClient.php(199):Aws\ClientResolver->resolve() #8 phar:///var/www/mail/aws.phar/Aws/S3/S3Client.php(346):Aws\AwsClie inphar:///var/www/mail/aws.phar/JmesPath/Lexer.php 在线343
PHP版本是7.4,我安装了simplexml扩展,正如Amazon所说,这是一项要求。
服务器是AWS Lightsail Ubuntu上的Apache。启用mbstring扩展(多字节字符串),正如Chris所建议的那样 确保已启用对PHP的支持。