This two-part article series aims to make a beginner understand using push queues with Laravel. To give a brief overview, the final solution which we will be looking at is a simple form to upload photos and resize them. Resizing images is a time consuming task, so instead of making a user wait until the image is resized we can do it in the background. At the same time, we’ll learn to use a tool called ngrok so that we can use queues in our local system.
The source code is provided at: https://github.com/phpmasterdotcom/laravel-queues
You can also try it in a proper live server.
Queues and Iron
A queue is nothing but a pipeline where we line up our jobs and they are executed in the order they are inserted. Let’s say currently our queue is empty and we put Job A into it, then we put Job B and Job C. We read the queue in the same order. First we take Job A from the queue and finish it, and then work on next one. If you focus on the “read” part, we always have to check our queue to see if any new job is posted. Wouldn’t it be better if the queue itself notifies us when a job is available ? Queues like those are called push queues, and that’s what we’ll be using with IronMQ.
Iron MQ is a service which makes our life easier when it comes to using queues. When you create a push queue you also need to mention a subscriber to that queue. A subscriber is nothing but a url which will be called when a job is available in the queue with the data originally provided to the job.
To read more about job queues and see comparisons between different solutions, see this article.
Setup and Installation
In this step we install Laravel and all required dependencies via composer. We also create an account at Iron and install a tool called ngrok.
Laravel
Install Laravel
composer create-project laravel/laravel --prefer-distAfter this command you should see the folder “laravel”. Open the laravel folder in your favorite text editor or IDE.
Go into the folder via the command line and run:
php artisan serveAt this point if you open http://localhost:8000 you should see the home page of your Laravel installation.
Set up the Database : We will use MySQL for our database. Create a database via the command line, phpmyadmin, or whichever tool you are comfortable with. After you created a database, go to
app/config/app.phpand find the section similar to the following:
Continue reading %IronMQ and Laravel: Setup%
more
{ 0 comments... » IronMQ and Laravel: Setup read them below or add one }
Post a Comment