PHPackages                             shankao/daemonizer - 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. shankao/daemonizer

ActiveLibrary

shankao/daemonizer
==================

0.1.1(10y ago)09PHPPHP &gt;=5.3.0

Since Nov 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/shankao/Daemonizer)[ Packagist](https://packagist.org/packages/shankao/daemonizer)[ RSS](/packages/shankao-daemonizer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Daemonizer
==========

[](#daemonizer)

This project aims to greatly simplify the creation of very lightweight system daemons in PHP, and hide the low-level details after a modern class-based interface.

Daemonizer implements a fast and simple main loop for you, so you don't need to take care of the details. A disadvantage of this is that you *must* let your class' run() function end from time to time (no infinite loops). Failing to do this will make your daemon unresponsive to external signals (i.e. sigterm)

Daemonizer uses a version of PEAR's System\_Daemon internally. Find it here: [kvz/system\_daemon](https://github.com/kvz/system_daemon)

### A very simple example

[](#a-very-simple-example)

Daemon that echoes a string once per second:

```
class example implements Daemonizer\Daemonizable {
  public function sleep_time() {
    return 1; // In seconds
  }

  public function run() {
    echo "Hey there!\n";
  }
}

$daemon = new Daemonizer\Daemonizer('example', '././example/example.pid');
// Add customizations. I.e: $daemon->set_logfn('my_logging_function');
$daemon->run(new example);
```

Find a sightly more complete example at

### About the PID location parameter

[](#about-the-pid-location-parameter)

Sadly, using System\_Daemon internally has its drawbacks. One of the most visible in Daemonizer is the way that the PID file location has to be indicated:

1. It **requires** to have at least two backslashes to start. In our example, the first part of "././example/example.pid" is only used to refer to the current folder. This requirement is due to System\_Daemon expecting PID's to be system-wide located, like in /var/run (see the two backslashes)
2. It **requires** that, after the two slashes, comes a folder with the same name as the daemon's name. In the example before, the "example" folder part. The reason is the same: System\_Daemon requires to follow a UNIX system-wide protocol for PID file locations.

This problems will be fixed with the depart from System\_Daemon in the future

### Customization functions

[](#customization-functions)

Call them for your Daemonizer object, before the call to run() to change some aspects of the daemon:

```
set_finishfn(callable $fn)
```

Set the function to call when the daemon receives a SIGTERM signal

```
set_restartfn(callable $fn)
```

Set the function to call when the daemon receives a SIGHUP signal

```
set_uid(int)
```

Force the daemon's UID to this one

```
set_gid(int)
```

Force the daemon's GID to this one

```
set_logfn(callable $fn)
```

Set the function to call for logging

```
set_loglevel(int)
```

Set System\_Daemon's logging level

### Next steps

[](#next-steps)

For next releases, I intend to keep the same functionality, without using System\_Daemon internally, as its code has become old and bloated. Given that I intend to keep Daemonizer simple and lightweight, that last part is not good. Also, the PID location quirk is painful for a real-world project.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~0 days

Total

3

Last Release

3822d ago

### Community

Maintainers

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

---

Top Contributors

[![shankao](https://avatars.githubusercontent.com/u/2804102?v=4)](https://github.com/shankao "shankao (32 commits)")

### Embed Badge

![Health badge](/badges/shankao-daemonizer/health.svg)

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

PHPackages © 2026

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