I have a single server running on rackspace which is hosting a single PHP web app.
The PHP web app will accept a form submission that then needs to perform a task based on the form field entries.
The task (let's called it the generate metadata task) requires quite a lot of processing time. I was wondering how to allow the form submission to be a straightforward save to database and immediately show success page to user while running the generate metadata task in the background.
I have installed "aws/aws-sdk-php": "~3.11" using composer into the same web app.
My plan is initially this:
code that handles the form submission
$result = $model->save($_POST);
// this code will send the information to either SQS or SNS
$awsClient->sendsMessage($_POST);
if ($result) {
$this->redirect('success.html');
}
I have read about the fanout architecture stated by AWS.
My issues with the fanout architecture example (as I understand it) are this:
- the server that sends the message to either SQS or SNS will also be the same server that processes the generate metadata task. In fact, it's the same web app.
- SQS fulfils the queue part (because I want to execute the tasks in a FIFO and the tasks do take a long time to fulfil). However, it requires my web app to poll SQS continuously. I want a push notification (from AWS to my web app) rather than my web app polling AWS continuously to check for tasks to execute.
I found a possible solution suggested here
The suggested solution is:
send the message to a SNS topic.
The SNS topic will message both a SQS queue and my web app.
My web app, after being triggered, will poll the same SQS queue that has now queued the message continuously until the queue is empty
The drawback I see from this is that my web app will poll the queue before the queue itself has the message.
What is the best way to implement push queues using AWS services?