Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Toptal.com:
Handling Intensive Tasks with Laravel
Apr 05, 2016 @ 12:48:36

The Toptal blog has a post for the Laravel users out there showing you how to handling intensive tasks in your applications. In this case it's creating a background job (run via cron) to import information from Excel spreadsheet formatted file into the database.

When dealing with time consuming resource intensive tasks, most PHP developers are tempted to choose the “quick hack route.” Don’t deny it! We’ve all used ini_set('max_execution_time', HUGE_INT); before, but it doesn’t have to be this way.

In today’s tutorial, I demonstrate how an application’s user experience may be improved (with minimal developer effort) by separating long-running tasks from the main request flow using Laravel. By making use of PHP’s ability to spawn separate processes that run in the background, the main script will respond faster to user action.

He starts with why PHP isn't particularly a good choice for long running requests and how making users wait for it to complete is a bad thing. He then walks you through the setup of a basic Laravel application that includes the maatwebsite/excel library for the Excel handling. He shows his configuration setup, both in the Nginx and Laravel side, to handle serving up the app. He uses Laravel migrations to set up the database and the models, routing and logic (controller) to handle the incoming Excel file for import. With this in place he then creates the command type to process the file and save the information it contains to the database. Finally, he ends the post with the cron configuration you'll need to handle the import, running it nightly at midnight.

tagged: tutorial intensive task excel import database laravel

Link: https://www.toptal.com/laravel/handling-intensive-tasks-with-laravel

SitePoint PHP Blog:
Crash Course of Wunderlist’s API with Guzzle
Jan 11, 2016 @ 11:14:31

The SitePoint PHP blog has a tutorial posted giving you a crash course on the Wunderlist API and using Guzzle to connect with it. Wunderlist is a task-tracking, to-do list kind of application with support for multiple platforms and, for developers, a nice and relatively easy to use API.

Wunderlist is one of the most popular task management and list keeping applications out there. It allows you to create lists to which you can then add tasks that are easily checkable and have all sorts of functionality built into them. It has native apps for all the major OS’s and all your data syncs effectively over the cloud. It’s very nice to work with if you are trying to keep yourself organized and you can get a lot done even with the free version.

They've posted the final product in a demo repository but they still walk you through the whole process of setting up a simple application that can get, submit and update data via the API:

  • Creating the Wunderlist class (a HTTP client)
  • Returning data using the Wunderlist API
  • Creating and updating data with the Wunderlist API

They also talk a bit more about the OAuth flow the API uses for authentication and points out that the repository also includes a bit more functionality allowing you to get a list and mark the items as complete with a little Ajax.

tagged: crash course wunderlist api guzzle tutorial task list todo

Link: http://www.sitepoint.com/crash-course-of-wunderlists-api-with-guzzle/

Laravel News:
Laravel Quick Start – Learn to build a task list
Oct 28, 2015 @ 09:46:44

On the Laravel News site they mention a new quickstart guide that's included in the official Laravel manual now, walking you through the creation of a simple "to do" list application and introducing you to the framework.

The Laravel documentation now includes a dedicated quick start section to guide you through creating a basic task list. For those new to the framework, this is an excellent guide to show you the basics but even the experienced can pick up new tricks. [...] To go along with the tutorial is a Github repo where you can view all the source and easily check it out to play around yourself.

The quickstart steps you through the entire process of creating the application, from a Composer create-project out to the task CRUD (create, read, update, delete) functionality. It shows the use of the Eloquent ORM, routing functionality, views, Blade templates and more. If you're new to the framework and want to check out what it's all about this is a great place to get started.

tagged: laravel framework qickstart task list todo introduction

Link: https://laravel-news.com/2015/10/laravel-quick-start-learn-to-build-a-task-list/

SitePoint PHP Blog:
Look, Ma! No NodeJS! – a PHP front end workflow without Node
Aug 20, 2015 @ 09:26:54

The SitePoint PHP has posted an interesting tutorial describing a Node.js frontend workflow without Node.js, instead using PHP tools to replace the Node.js functionality needed for the build.

If you’re intimidated, exhausted or irritated by Gulp, Grunt, NPM, Yeoman, and all the other NodeJS tools that aim to help but often do the opposite, a good asset management workflow is possible in PHP, and this tutorial aims to prove it. In this article, we’ll go through a NodeJS-free PHP front end asset management setup.

He uses three tools to create the build process: BowerPHP for installing assets, markstory/mini-asset for minification and Robo for automation. He sets up a Homestead virtual machine instance as a testing ground first then creates a basic Slim-based application from the slim3-skeleton package. He gets the necessary tools installed via Composer then gets into the details of the process. He adds (Twitter) Bootstrap into his assets, shows how to set up the minification and creates a Robo task to watch the CSS for any changes. This task then re-runs the minifaction on the CSS and created the condensed version automatically.

tagged: workflow nodejs bowerphp miniasset minification robo task tutorial

Link: http://www.sitepoint.com/look-ma-no-nodejs-a-php-front-end-workflow-without-node/

Stephan Hochdörfer:
Running PHPUnit via Phing on HHVM
Feb 26, 2015 @ 09:16:58

Stephan Hochdörfer has a quick post showing how he has PHPunit up and working on an HHVM instance. His problem was that the tests were actually executing using the "php" binary, not the HHVM one.

For quite some time we run the unit tests for our libs and tools against PHP and HHVM, at least that is what I thought up to now. As it turns out I missed a minor detail. [...] What happens now is that Phing is executed via HHVM but PHPUnit will still be executed via the PHP binary because the PHPUnit shell script will look for the php binary in the PATH configuration. Since we run HHVM side-by-side with PHP on our Jenkins build nodes I was not able to point /usr/bin/php to /usr/bin/hhvm - which would be the easiest and cleanest solution. I

He shares the workaround he created, creating a symbolic link between the hhvm and php binaries and then executing the Phing task to run the tests. This is being run via Jenkins and uses it's "WORKSPACE" as a container so the main "php" binary isn't overwritten.

tagged: hhvm phpunit test unittest execute binary path jenkins phing task

Link: https://blog.bitexpert.de/blog/running-phpunit-via-phing-on-hhvm/

Stephan Hochdörfer:
Defining Phing Tasks in PSR-0 style
Jan 23, 2015 @ 10:42:49

In his latest post Stephan Hochdörfer shows you how to define Phing tasks according to the PSR-0 autoloading format. Phing is a PHP-based automation tool that uses an XML configuration to execute a series of tasks.

Before anybody complains: I know that "as of 2014-10-21 PSR-0 has been marked as deprecated. PSR-4 is now recommended as an alternative." - Anyway I still think this little gem makes sense to be shared because a lot of people are probably not aware of it. I recently found out by accident that it is possible pass a task name in PSR-0 style to the "taskdef" task. In the old days you had to use the Java-like dot-style notation like this and also define the classpath to make sure the class could be loaded correct! This is ok if the task resides in the same project. If the task is located in a dependent package loaded via Composer this can get ugly.

The post is quick but provides two very handy code examples, one showing the old "dot notation" version and the other showing how to make use of the autoloader. The trick is in the classname value and using the full namespace/class name rather than the dot notation.

tagged: phing build task psr0 classname path autoload

Link: http://blog.bitexpert.de/blog/defining-phing-tasks-in-psr-0-style/

Matthias Noback:
From commands to events
Jan 09, 2015 @ 10:43:09

Matthias Noback is back with another post in a series looking at using a command bus to execute more complex code in somewhat of an isolation from the rest of the application. In this new post he moves on to some of the secondary tasks that happen inside the commands and how those relate to event handling.

In the previous posts we looked at commands and the command bus. Commands are simple objects which express a user's intention to change something. Internally, the command object is handed over to the command bus, which performs the change that has been requested. While it eventually delegates this task to a dedicated command handler, it also takes care of several other things, like wrapping the command execution in a database transaction and protecting the original order of commands.

He gets into some of these secondary tasks inside of the commands themselves - smaller actions that need to be done as a part of the execution of the command as a whole. He points out that it's tempting to do everything inside the command, but that it can lead to maintenance issues down the line. He suggests that the command shouldn't perform these tasks at all. They should be handled by an event system that uses event objects to pass off responsibility for performing actions to other objects (for example, handling the post-signup process once a user is created). He's done some research on some event dispatchers currently available but found them lacking in one way or another. Instead he opted to integrate one into his SimpleBus library (EventBus) to provide an integrated way of handling these secondary events. An example of it in use is also included.

tagged: commands events commandbus simplebus secondary task dispatch

Link: http://php-and-symfony.matthiasnoback.nl/2015/01/from-commands-to-events/

Dutch Web Alliance:
Capifony, Continuous Deployment and Symfony’s parameter.yml
Dec 15, 2014 @ 12:10:50

On the Dutch Web Alliance site today they've posted a tutorial about their use of Capifony for Symfony application deployment and how it relates to updating the "parameter.yml" file. They describe their current deployment process, how it works with the different environments and how they solved the one manually problem they had.

The actual deployment is thus dealt with by capifony. This is a plugin for capistrano written for deploying Symfony applications. [...] Capifony automatically deals with cloning the correct branch on the servers, installing dependencies through composer, migrating database versions etc etc. Basically we don’t have to care about anything else. However, there is one single thing that still keeps on bugging us: when we want to upgrade to a new parameters.yml, we must do this manually. This means that our builds will break when we deploy a version that requires an updated parameters.yml until we manually solve the issue.

To get around this manual issue, they decided on creating a new Capifony task that does an upload/download of the parameters file, depending on the environment.The continuous deployment can then push or pull the file as needed in a more automatic way.

tagged: continuous deployment paramatersyml configuration capifony capistrano task

Link: https://dutchweballiance.nl/techblog/capifony-continuous-deployment-symfonys-parameter-yml/

SitePoint PHP Blog:
PHP Job Interview Task: Day of Week Calculation
Jan 09, 2014 @ 12:14:56

Sometimes during an interview it's difficult to determine the skill set of the person on the other side of the table. One solution to this that's become popular is asking the developer to perform a task of your choosing and watching how they work out the problem. In this new post to the SitePoint PHP blog Bruno Skvorc shares one suggestion for this kind of test - a day of week calculation.

Not so long ago, I was given a job interview task. I was to write a function which deduces the day of the standard 7-day week of ANY calendar (even an imaginary one), provided I know how often leap years happen, if at all, how many months their year has, and how many days each month has. This is a fairly common introductory job-interview task, and in this article I'll be solving and explaining the math behind it.

His task was, given any kind of calendar definition (not necessarily the Gregorian), figure out what day of the week a certain month/day/year combination would fall on. He walks through the entire code to solve the problem, including a bit to output the resulting calendar to an HTML table for each month.

tagged: interview task dayofweek calculation tutorial

Link: http://www.sitepoint.com/php-job-interview-task-day-week-calculation

SitePoint PHP Blog:
Introduction to Gearman - Multitasking in PHP
Nov 04, 2013 @ 13:23:11

The SitePoint PHP blog has posted an introductory tutorial showing you how to use Gearman in PHP to handle multitasking outside of the normal script execution. Gearman is an external job server that lets you schedule scripts and tasks for execution.

How many times have you developed a web application that had some functionality which would benefit from running an external program or even forking a separate process? This is not something you generally like to do from your web app because you want to make it run as fast and efficient as possible, while keeping the site functional for end users. So how do we get a fast but full-featured application that can process more than the average app we're used to?

They start by introducing you to Gearman - the server side - and how it works to handle a large amount of jobs quickly (50 thousand per second according to the article). They give the example of resizing images uploaded by users to illustrate. Next up is the installation - first Gearman then on to the PHP side, installing the PECL extension and adding it to the php.ini configuration. An example script is also provided showing how to create a new connection to Gearman and configure the callbacks for handling status changes. They also include adding two kinds of tasks - a normal one and a low priority one.

tagged: tutorial gearman introduction install configure process task

Link: http://www.sitepoint.com/introduction-gearman-multi-tasking-php/