简体   繁体   中英

AWS PHP SDK getting class not found fatal error

I'm trying to read messages from my SQS but I can't get that far as I'm having trouble installing the PHP SDK.

I followed the instructions and installed via composer.

My code for testing purposes is:

require 'vendor/autoload.php';
$sqs_credentials = array(
        'region' => 'us-west-2',
        'version' => 'latest',
        'credentials' => array(
            'key'    => '*****',
            'secret' => '**********',
        )
    );

    $sqs_client = new SqsClient($sqs_credentials);

This simply results in

Class 'SqsClient' not found in /var/www/html/sqs_test.php on line 10

I then tried by downloading the zip file directly and used

require 'aws/aws-autoloader.php';

This resulted in the exact same error. What am I doing wrong? I'm quite certain the path is accurate as I can output text directly on Sqs/SqsClient.php.

Still not sure why the above didn't work, but if anyone is trying, this does work:

require 'vendor/autoload.php';
use Aws\Sqs\SqsClient;

$client = SqsClient::factory(array(
        'region' => 'us-west-2',
        'version' => 'latest',
        'credentials' => array(
            'key'    => '********',
            'secret' => '********',
        )
    )
);

$result = $client->receiveMessage(array(
    'QueueUrl' => $sqs_url
));
print_r($result);

The class you're trying to instantiate is namspaced. Remember to include a use Aws\\Sqs\\SqsClient; statement before referring to the class by its short name.

Somewhat related but not exactly this issue. I had a class not found for Aws\\Sns\\MessageValidator (& Message) and after some struggle found out that latest SDK v3.17.3 for PHP didn't have them under \\Sns - https://github.com/aws/aws-sdk-php/tree/3.17.3/src/Sns . I simply rolled back to an earlier version 3x and corrected the import path to get the class we needed. Posting here thinking it may of help to someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM