PhpTaskDaemon: An introduction

PHP is most often used for developing web based applications. But PHP can also be used for developing starting scripts using the command line. Scripts can easily be run as cron jobs, daemons, gearman workers and some other techniques to execute a set of tasks periodically, on-demand and/or parallel. In this blog post I introduce a new open source project I started for developing a php daemon/process starter. Before I start rambling about the project, called PhpTaskDaemon, I will explain more about the problem I try to solve and the current available technologies for solving the same problem. After this I will explain more about the project itself and the problem it tries to solve. Finally I will outline the project requirements and introduce the future blog post.

What? Using PHP for something else than generating HTML? In some cases it is desirable to run a PHP script periodically to do system administrative tasks. For example: periodically delete old database records, collect new information from the Internet, talk to a serial device to control your power outlet wireless and all kind of other scripts. Two differences with developing web applications are the time a process can take and the way scripts/functions are triggered. A process can even take forever using a simple while(true) statement.

Running PHP in the background There are different ways to run PHP as a background process. Below is a list of possible solutions.

In some of my projects I need to start multiple gearman workers and/or a combination of the process types mentioned above. When the number of tasks and/or instances increase it is hard to start and monitor all processes. I would like to see an easier solution to start and monitor multiple background tasks with different triggers. The solution I propose tries to abstract the listed examples in a single executable script.

The Project PhpTaskDaemon is a library for creating php daemons for unix environments (requirement: pcntl and posix extension). It provides a simple api consisting of two methods for defining the loading of a task queue and the execution of a single task. The tasks are run by a manager, which defines the way when and how tasks are executed. A single command line script is used to start, stop and monitor the daemon. The features and requirements and wishlist of the application is listed below. The source code of the project can be found on GitHub.

Features

Requirements

Wishlist

Blog posts in this series This blog post is an item in a series of blog posts about the development of the PhpTaskDaemon project. Follow the real progress of the project on the GitHub project page. The following blog posts of this series have been published in the past:

Next time I will blog about the following aspects of the PhpTaskDaemon system.

Rendered Content in 0.003 seconds

Rendered UI Widgets in 0.003 seconds

Want to see the cheezy internals?
twig layout template | twig page template | json data