PHP-Task: Basic Ideas

In the year 2015 I had the idea that symfony applications should be able to schedule and run tasks in the environment of the application itself.

After a few days of research I only found some wrapper for Gearman or other task-runner. But all of this had a one main problem, the developer is not able to schedule tasks in the future. Besides of that this task-runner all needs to run additional software which has to be managed and maintained.

PHP-Task solves that problem by implementing all the parts in raw PHP, integration into symfony with a simple bundle and a storage layer for relational-database with doctrine.

Core Concept

The main parts of the library consist of the "TaskScheduler" and the "TaskRunner". The scheduler manages tasks and create their executions. The runner fetches the pending executions and uses so called, handlers to execute them. These handlers are simple PHP-Classes which take the workload of the execution and returns a result. An example would be a thumbnail generation task - where the workload contains the filename and the handler returns the path to the generated thumbnail.

In a symfony environment the handler is a simple service which can uses other services inside the dependency-injection container. This enhances the developer to reuse application code without any overhead.

In a real world example the runner will be called in a fixed interval (something like 5 minutes). 


A few weeks ago the project was released in the version 1.0.0. With this release PHP-task was integrated into Sulu. Read more about how the project is used there in the bog-post: "New in Sulu: Automation".