PHPackages                             basarevych/task-daemon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. basarevych/task-daemon

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

basarevych/task-daemon
======================

Simple PHP daemon library

v0.2.6(11y ago)430MITPHPPHP &gt;=5.4.8

Since Mar 25Pushed 11y ago2 watchersCompare

[ Source](https://github.com/basarevych/task-daemon)[ Packagist](https://packagist.org/packages/basarevych/task-daemon)[ Docs](https://github.com/basarevych/task-daemon)[ RSS](/packages/basarevych-task-daemon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (11)Used By (0)

Task Daemon
===========

[](#task-daemon)

Simple PHP fork()ing daemon which runs taks in the background. It uses Gearman internally, but it is not exposed to the user.

Installation
------------

[](#installation)

This daemon requires a running Gearman server and the following PHP extensions:

- pcntl
- posix
- openssl
- gearman

Add to require section of your composer.json:

```
    "basarevych/task-daemon": "0.2.*"

```

Examples
--------

[](#examples)

Have a look at Example directory.

- ReverseWordTask.php - our example task
- InfiniteTask.php - another example (infinitely running)
- The rest is our example programs

```
Initialize:
> git clone https://github.com/basarevych/task-daemon
> cd task-daemon
> ./composer.phar install
> cd Example

Start or restart the daemon:
> php 1.start-the-daemon.php

Print 'foobar' in reverse:
> php 2.reverse-word-task.php foobar

Launch our long running task:
> php 3.infinite-task.php

Terminate:
> php 4.stop-the-daemon.php
```

You can run steps 2 and 3 several times, but if the task is already executing (and is not terminated yet) running it again will do nothing.

Methods
-------

[](#methods)

- **static TaskDaemon::setOptions()**

    The options:

    ```
      'namespace' => 'TaskDaemon',                // Set to your project name
      'num_workers' => 10,                        // Number of parallel workers
      'pid_file'  => '/var/run/local-daemon.pid', // PID file path
      'debug' => false,                           // Make the daemon print debug info
      'gearman' => [                              // Gearman options
          'host' => 'localhost',
          'port' => 4730,
      ],
    ```

    **NOTE** 'namespace' and 'pid\_file' must be the same among all scripts that share the same daemon.

    **NOTE** If 'debug' is false (the default) then no text output from the daemon or its tasks will be printed to console.
- **static TaskDaemon::getInstance()**

    Get daemon instance (the class is Singleton)
- **defineTask($name, $object)**

    Define a task. **$name** should be a unique string and **$object** must be an instance of a class derived from **AbstractTask**.
- **runTask($name, $data = null, $allowDuplicates = false)**

    Run previously defined task. **$data** will be passed to the task (could be an integer, string or array).

    If **$allowDuplicates** is true, several tasks of the same name and the same data could be run at the same time.

    For example, while runTask('task1', "data1") is executing call to the same task: runTask("task1", "data1") will be ignored. But task with a different name or data: runTask("task1", "otherdata") or runTask("task2") will be run.
- **ping()**

    Return true if we are connected to Gearman server.
- **getPid()**

    Returns PID of the daemon or false if the daemon is not running.
- **start()**

    Fork() to the background and start executing jobs. Could be called several times as only the first run will fork().
- **stop()**

    Terminate the daemon and its workers
- **restart()**

    Restart the daemon

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

10

Last Release

4048d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ffb3982991e2fdfc78bbe9460affc1181d9b7d991c793516ab4db3f47cddbd78?d=identicon)[ross](/maintainers/ross)

---

Top Contributors

[![basarevych](https://avatars.githubusercontent.com/u/3628063?v=4)](https://github.com/basarevych "basarevych (27 commits)")

---

Tags

phpdaemon

### Embed Badge

![Health badge](/badges/basarevych-task-daemon/health.svg)

```
[![Health](https://phpackages.com/badges/basarevych-task-daemon/health.svg)](https://phpackages.com/packages/basarevych-task-daemon)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
