Rajiv is an enthusiastic web developer and product developer. He is a Computer Science Engineer from India. He loves PHP and has a deep affection for Laravel. He loves exploring new technologies. In his free time he reads technical articles written for PHP and tries to contribute to the community.

Rajiv's articles

  1. IronMQ and Laravel: Delays and Retries

    This entry is part 3 of 3 in the series IronMQ and Laravel

    Previously, we saw how to use Iron push queues with Laravel. All we needed to do was set up an Iron account, add a subscriber URL, push a message to queue, and receive the message.

    The way Laravel supports Iron push queues out-of-the-box is amazing, but there are always limitations. In this article we focus on those limitations and learn to tackle them.


    There are three possible scenarios:

    1. You received the message and you finished the job successfully.

      • You need provision to tell Iron that the job was completed successfully and it needs to delete it from the queue.
    2. You received the message and something went wrong. Basically, your job was not successful.

      • In this case we should tell Iron that we failed and it should retry or if you couldn’t tell Iron anything, it should be clever enough to retry the job i.e., push the same message again to your subscriber after some time.
    3. You received the message, but your job is a long running process (something which takes more than a minute)

      • Iron should wait longer before it resends the message.

    These are all practical scenarios and you will face them on a daily basis. And yes, you need to cover these cases in your applications.

    It’s possible to use Iron to its full power if we use the Iron MQ PHP Library. During setup we included "iron-io/iron_mq": "1.4.6" in our composer file. The code for the same is hosted at https://github.com/iron-io/iron_mq_php. Let’s take a peek into the documentation and try to understand how to use this library.

  2. IronMQ and Laravel: Implementation

    This entry is part 2 of 3 in the series IronMQ and Laravel

    Welcome back to the IronMQ and Laravel series – this is the second and final part in which we finalize our background-job enabled web app.

    There are several tutorials out there related to queues already – for example: http://vimeo.com/64703617 where Taylor teaches you how to write to a file using queues. In this tutorial, we will try something different.

    We will make a jobs table which has job_id, and the status of the job. When you put a job on the queue, the job status will be queued and when we receive the job, we set the status to running. Accordingly, after finishing it we will mark it finished.

    Later, we will resize images.

    Jobs Table

    Step 1

    Let’s create a jobs table:

    php artisan migrate:make create_jobs_table

    Go to app/database/migrations/xxxxx_create_jobs_table.php and add the following (This code is extracted from app/database/migrations/xxxxx_create_jobs_table.php, so edit your file accordingly):

    public function up()
        Schema::create('jobs', function($table)
        $table->enum('status', array('queued', 'running','finished'))->default('queued');
    public function down()

    Here we created a table with the columns job_id, status and timestamps. Run php artisan migrate to create the table.

    Step 2

    Create a file job.php in app/models with the following content:

    class Job extends Eloquent {
        protected $table = 'jobs';
        protected $fillable = array('job_id', 'status');

    Make a JobController using the following command:

    php artisan controller:make JobController

    and add the following in the app/routes.php file:


    Go to JobController populate the index method.

    public function index()
        $jobs = Job::all();
        return View::make('job.index')->with('jobs',$jobs);
  3. IronMQ and Laravel: Setup

    This entry is part 1 of 3 in the series IronMQ and Laravel

    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.


    1. Install Composer.

    2. Install Laravel

      composer create-project laravel/laravel --prefer-dist

      After 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 serve

      At this point if you open http://localhost:8000 you should see the home page of your Laravel installation.

    3. 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.php and find the section similar to the following: