PHPackages                             ustream/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. ustream/daemon

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

ustream/daemon
==============

Ustream daemon

1.0.0(12y ago)8442MITPHPPHP &gt;=5.3

Since Aug 28Pushed 11y ago32 watchersCompare

[ Source](https://github.com/ustream/daemon)[ Packagist](https://packagist.org/packages/ustream/daemon)[ RSS](/packages/ustream-daemon/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Ustream\_Daemon [![Build Status](https://camo.githubusercontent.com/d71467263b8ebec56c9fd174143907074f1f61489aa200e88d6c2ec488169cf7/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7573747265616d2f6461656d6f6e2e706e67)](http://travis-ci.org/ustream/daemon?branch=master)
========================================================================================================================================================================================================================================================================================

[](#ustream_daemon-)

`Ustream_Daemon` is a library for running php code as daemons. It works around php's limitations in this area and implements some sane default behaviors. The main goal is to provide a robust way of running php code continously while decoupling the business logic from the details of running a background task. We hate superflous boilerplate like everyone else so the daemons have a common entry point.

Download
--------

[](#download)

Github:

Composer:

```
composer require ustream/daemon:~0.1.0

```

Versioning
----------

[](#versioning)

We follow the guidelines on

Features
--------

[](#features)

- contexts
- extensible via symfony event dispatcher

Usage
-----

[](#usage)

We recommend using the library with a single entry point per project. Creating this entry point is up to you, it should bootstrap your application as you need it, then call the daemon runner class:

```
require 'bootstrap.php';

$runner = new Ustream_Daemon_Runner();

$runner->runDaemon(
	__DIR__ . '/run', // run directory, pids are stored here
	'production',     // context it is used to suffix log filenames and pidfiles
	__DIR__ . '/ini', // ini directory, the configuration files are stored here
	array()           // event listeners
);

```

You can start a daemon by calling this entry point with the --id="daemon-name" parameter. The config file daemon-name.ini is used from the provided ini directory to configure the daemon.

Daemon configuration
--------------------

[](#daemon-configuration)

The most important is to specify a factory method, which returns an object implementing the `Ustream_Daemon_Task` interface. The interface itself has only one method, `doTask()` - you should specify what the daemon should periodically do in this method. This is the only required element of the ini file, the others are optional.

- factory : A string specifying a class and static factory method to get the task
- sleep : An integer, specifying the period length of the `doTask()` runs. The daemon waits this many seconds (substracting the real execution length of the `doTask()` method, so it normally won't accumulate delay)
- min-sleep : Another integer value in seconds, specifying the minimum break between two runs. This is useful if the task itself causes something (like system load for example) which needs a bit break even if there would be not enough time before the next run.
- memory-limit : Specified as the php shorthand notation for bytes (see [the manual](http://hu1.php.net/manual/en/faq.using.php#faq.using.shorthandbytes) ). This will be set as `memory_limit` via `ini_set`
- memory-threshold : A value between 0 and 100. It specifies the part of the above memory-limit which is allowed to be used by the daemon, in percents. The runner checks the memory usage after each run and exits the process if it is exceeded.
- log-dir : A path to a directory where the daemon should put its log file.
- common-log : A path to a common log file where the daemon handler itself writes some logs (like when it starts or stops a child process). Typical use case for it is to have one file which is used by all daemons and logs their starts and stops.

An example configuration ini file:

```
factory=Ustream\EditorialMetrics\LogProcessor::create
sleep=0
min-sleep=0
memory-limit=256M
memory-threshold=70
log-dir=/var/log/custom_php/
common-log=/var/log/custom_php/daemon_util.log

```

Events
------

[](#events)

The daemon dispatches two events. One on startup, and one on each completion of its task. The event identifier constants are defined in the `Ustream_Daemon_Event` class. You can add listeners to these events via the `addListeners()` method. An example:

```
$daemon->addListeners(array(
			Ustream_Daemon_Event::START => array(
				array($onStartListener, 'onStart'),
			),
			Ustream_Daemon_Event::TASK_DONE => array(
				array($onTaskDoneListener, 'onTaskDone'),
			)
		);

```

The events are dispatched via symfony's event dispatcher, which basically means that the listener object's specified method will be called with an event object as parameter. More info about this in the [symfony manual](http://symfony.com/doc/current/components/event_dispatcher/introduction.html)

Contributing
------------

[](#contributing)

Please see CONTRIBUTING.md for details.

Credits
-------

[](#credits)

Ustream\_Daemon is maintained by [ustream.tv, inc](http://ustream.tv/)

Authors:

- [Tamas Ecsedi](https://github.com/ecsy)
- [Zoltan Nemeth](https://github.com/syntaxerror13)
- [Gergely Hodicska](https://github.com/felho)
- Zoltan Szabo
- [Zsolt Takacs](https://github.com/oker1)
- [Peter Wilcsinszky](https://github.com/pepov)

License
-------

[](#license)

Ustream\_Daemon is Copyright © 2013 Ustream Inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~99 days

Total

2

Last Release

4591d ago

Major Versions

0.1.0 → 1.0.02013-12-05

PHP version history (2 changes)0.1.0PHP &gt;=5.3,&lt;5.5

1.0.0PHP &gt;=5.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/431237?v=4)[Zsolt Takacs](/maintainers/oker1)[@oker1](https://github.com/oker1)

![](https://avatars.githubusercontent.com/u/682440?v=4)[Peter Wilcsinszky](/maintainers/pepov)[@pepov](https://github.com/pepov)

---

Top Contributors

[![oker1](https://avatars.githubusercontent.com/u/431237?v=4)](https://github.com/oker1 "oker1 (5 commits)")[![syntaxerror13](https://avatars.githubusercontent.com/u/1536254?v=4)](https://github.com/syntaxerror13 "syntaxerror13 (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k869.4M8.5k](/packages/symfony-http-kernel)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[symfony/mailer

Helps sending emails

1.6k409.1M1.4k](/packages/symfony-mailer)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k39](/packages/civicrm-civicrm-core)[phpro/soap-client

A general purpose SoapClient library

8896.1M53](/packages/phpro-soap-client)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)

PHPackages © 2026

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