Laravel 4 + IronMQ Push Queues = Insane Goodness
Laravel is an increasingly popular PHP framework with a strong and growing following.
If you’re a PHP developer, it’s a framework to seriously explore if not dig in and put to good use. The design principles are centered around a clean framework that uses a simple, expressive syntax.
About Laravel
There are a number of ways that make Laravel a special framework for PHP developers. Some of the features include:
- Bundles – Bundles are Laravel’s modular packaging system. The Laravel Bundle Repository is populated with quite a few features that can be easily added to any application. Developers can either download a bundle repository to their bundles directory or use the “Artisan” command-line tool to automatically install them.
- Eloquent ORM – The Laravel object-relationship mapping is the most advanced PHP ActiveRecord implementation available. With the capacity to easily apply constraints to both relationships and nested eager-loading, developers have complete control over their data with all of the conveniences of ActiveRecord. Eloquent natively supports all of the methods from Laravel’s Fluent query-builder.
- Application Logic – Application logic can be implemented within applications by either using controllers or by injecting directly into route declarations by using syntax similar to the Sinatra framework.view more >>
Laravel + IronMQ: The Benefits
Using a message queuing service with PHP applications is a great way to speed up your app (by pushing work to the background) as well as gain greater agility (by decoupling your code and making processes more independent). This solid 3-tier architectural underpinning can be achieved right from the start using IronMQ. (IronMQ is a cloud-based service that is instantly and always on. Which means you don’t have to set-up or manage servers or worry about things like high availability or redundancy. All that is managed by Iron.io.)
Offloading Tasks
By moving tasks to the background – things like sending emails, posting data, transforming images, running reports, accessing accounts, or performing calculations – you can return control back to the user much more quickly and provide a much more responsive experience.
For many tasks, there may not be a user acknowledgement; for others, a call-back or a non-intrusive front-end polling cycle can retrieve the information once the task is done and the information is ready to be presented.
Decoupling Processes
By decoupling processes, you make the front-end more independent from the processing layer and make each process independent from each other. In this way, changes in one type of worker (sending an email for example or creating a thumbnail) will have little to no impact on any other parts of the application.
It also makes it much easier to add new features. If you want to add another action to an event, you can add another queue or in the case of push queues, add another subscriber. The process sending the event/message doesn’t need to know about the new subscriber and neither do the other subscribers (unless you want them to in which case you can use a chain of queues to sequence the work).
Laraval 4 and IronMQ: Using Push Queues
Push queues allow you to post messages/data to a queue and have that queue push the data to one or more URLs. Laravel 4 and the IronMQ bundle provides an easy way to marshal that request into the queuing process. This means that you can do lots of asynchronous processing without a lot of overhead or added work.
Here’s documentation on using queues within Laravel 4.
Laravel 4 : Documentation : Queues
Here’s a short video that goes through the process from creating a queue to push messages to a URL.
Using Iron.io push queues in Laravel 4 |
This demo also addresses pushing a closure onto a queue for another process to run. A Closure is a PHP 5.3 class that represent anonymous functions (i.e. functions which have no specified name). They are useful as the value of callback parameters, but they have many other uses. (This is all made possible by the use of a new feature in Laravel 4 called serializable closures.)
Other Queueing Options
You do a lot more with queues and background processing. A few of these options include:
- having multiple subscribers on a queue
- posting and getting multiple messages at time
- polling or using scheduled jobs to process tasks from the queue
- chaining queues
Here’s what a few in the Laravel community are saying about the combination:
The People Behind Laravel
Taylor Otwell (@taylorotwell) began creating Laravel in April of 2011. He needed something that was up-to-date with the latest PHP 5.3 has to offer all the while maintaining a low barrier of entry through simplicity and great documentation. Not being able to find what he needed, he began writing a framework that was powerful and flexible, yet intuitive and expressive. A few months later, Laravel was born.
Laravel is open-source software and all of the code is available on Github and so anyone can contribute. From the looks of the growing number of bundles available, people certainly are.
In Praise of Developers
It takes a lot to build and launch a web framework especially within a large and established community like the PHP world. We have some strong developer respect for the creators and contributors of Laravel.
Well played, Laravel. Very well played.