This post is also available in: Englisch Französisch Italienisch Spanisch
To a lot of users, Press Loft may seem like just a simple image gallery that journalists can use to download images, and whilst this is true there is so much more happening behind the scenes to keep the whole operation running smoothly.
One system that we rely on is CRON. It’s simply a job-scheduling tool that allows us to write a script for a task we want completing and then have that triggered at any particular time. For example we could write a script to send out a weekly email to our journalists, and then tell the system to trigger it every Monday at 8am.
Now we’d been trucking along quite nicely simply adding scripts and CRON commands as we need them. However as Press Loft has grown, the system became quite a challenge to maintain. Testing and debugging became more and more difficult, and we now had to take into account the strain all these running scripts would have on the website’s performance.
We thought enough was enough and it time for us to move onto something new!
Time for that sweet MVC.
Over the past few months we have been looking into ways of making Press Loft more scalable and cloud based, and we are always refactoring our code to bring the site up to modern standards.
With this in mind, we decided that utilising a framework would be a step in the right direction to make our task scheduling easier to manage and scale.
Laravel has set alight the PHP world with its elegant syntax, modern toolkit and an amazing community of developers. It has become one the most popular frameworks for the development of modern applications. But the main reason it looked appealing to us was the task scheduling service built into the framework, so we thought this would be a perfect match!
The framework allows us to elegantly define the tasks that we would like to run all from one place. The sure beats the old way where we would have to define a new CRON entry for every task we would like to add. Here is an example of what a task command might look like:
All this line of code does is tell the server to trigger the command ‘emails:send’, which is a reference to a script that we have written within the framework. The daily() function tells the system to trigger the email daily (because journalists receive the email at different times of the month) at 7:30am. Finally we use the weekdays() function to tell the system to only trigger the emails Monday to Friday.
Get our head in the clouds…
One of the other key goals of this exercise was to take some load of the servers that the website runs on. Previously, all of CRON scripts and website code were all stored on the same server. This lead to some potential performance concerns when we were scheduling a script that had to process a lot of data.
So with this in mind, we decided to install the framework on a separate cloud server that works independently of the website. This means we can run larger scripts and process data without the burden of worrying too much about the performance of the main website.
With this transition to cloud, we are also safe in the knowledge that we can scale our resources much easier than before. So as Press Loft grows, so can our servers!
This project has taught what is possible when we fully utilise modern programming techniques and cloud technologies. So expect this to be the standard of Press Loft as we move forward.
Header Image: Life is beautiful Cushion Natural | indie art & design