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.

Answers


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.


Need Your Help

Audio Stream from PC/Mac to Android/iPhone

streaming hosting mp3 audio-streaming jplayer

Firstly, as this is essentially a multi-disciplinary question, please feel free to submit answers which only answer one part of the post - I will upvote answers which satisfy any of the questions b...

how to use a procedure in a SQL script?

mysql syntax debugging

If i run every block of this script in mysql-query-browser, it works.