Blog

Search This Blog

Loading...

Monday, July 15, 2013

Yii + IronMQ = Yiiron → Giving a Powerful PHP Framework Even More Juice


Yii is a high-performance PHP framework designed for developing scalable applications. It  is a well proven and stable framework with a large following.

Yii comes with rich features – MVC, ActiveRecord, internationalization, caching, authentication,  role-based access control, scaffolding, testing, more. All these features translate into drastically reduced app development times, more readable code logic, and greater application stability and scale. A nice win if you ask us.

What makes Yii even cooler is that it now has Iron.io services integrated into it via Yiiron. IronMQ, IronWorker, and IronCache are all supported via this package. In terms of IronMQ, this means that adding high-performance cloud-based message queuing is about as simple as adding config items to point to the IronMQ endpoints. (It's the same in regards to an elastic task queue with IronWorker and a key/value data store with IronCache.)

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

We'd love to be able to take credit for this integration but it was all the doing of John Eskilsson (aka br0sk on GitHub). John is a freelance systems architect and web developer. He's currently working for Edeva AB, an innovative Swedish company working on intelligent traffic solutions. They make extensive use of IronMQ and IronWorker, moving data from the speed bumps to the central system and for performing analytical calculations and backups.

Here is an excerpt from the Yiiron ReadMe:

Yiiron and the Work of John Eskilsson




Configuring IronMQ

1) Create an Iron.io account
If you don’t already have an iron.io account please sign up for a free account at Iron.io.

Go to the Iron.io dashboard (hud.iron.io/dashboard) and create a new project.

When the project is created, click the key icon and take a note of the token and the project id.

2) Install Yiiron into your app
Unzip the yiiron.zip file that you downloaded from the Yiiron Yii extension page and put all the files in the extensions directory. It would look something like this:

    /var/www/myapp/protected/extensions/yiiron

Note: You can also install the the extension using Composer. It uses the new Yii Composer installer. Remember to set the composer flag for the extension to false if you used the zip file and set it to true if you have installed using composer. This is needed since the iron.io classes will be found in different locations based on how it was installed.




Add the following to your config file (don't forget to add it to the console.php if you want to use the IronWorkers)

    import'=>array('ext.yiiron.*',)

Add this to the component section...

    'yiiron'=> array(
        'class' =>'EYiiron',
        'token'  => ‘your_iron_io_token’,
        'projectId'  => 'your_iron_io_project_id',
        'services'   => array('mq','worker',’cache’),
        'composer'  => false,
        'workerFileCopyOptions' => array('exclude' => array('.git','.csv','.svn',  
          '.zip', "/runtime", "/config")),

        'configFile' => 'config/console_ironworker.php'
        ),


Now test it by adding this to one of the actions in a controller:

    Yii::app()->yiiron->mqPostMessage("yii_demo", "First Value");

Load the action in a browser.

Now go to the back to hud.iron.io/dashboard and click the MQ button next to the project you created. If everything is fine you should see a “Queues” tab. Click it!

You should now see your freshly created queue with one message added.

Congrats. Everything should be working now and you should be ready start to using Iron.io services!

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Yiiron Demo Application

John has created a pretty awesome Yiiron Demo Application that shows the power of concurrency. It lets you run tasks on a single server setup vs a mult-worker scale out framework. Powered by Yii Framework and Yiiron using IronWorker under the hood. (Ed. – Impressive stuff!)

Yiiron Demo Application


––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Other Services: IronWorker and IronCache

Yiiron also has integrated support for IronWorker and IronCache so Yii developers can get immediate access to highly scalable task queue and an elastic key-value data cache service. 

We're indebted to John and his work to integrate Iron.io services into Yii. The amount of enhanced tools and sophisticated frameworks around PHP is bringing new life into one of top languages for the web. It's great to see and it's great to be a part of some powerful new possibilities.  


UPDATE: Note John's comment below on why this extension is so different and special. (Thanks, John!)