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

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

apolinux/daemon
===============

Daemon manager similar to unix system daemons

v0.40(6y ago)04PHP

Since Mar 24Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Process and Daemon manager
==========================

[](#process-and-daemon-manager)

Create system daemons process. A daemon program is a special system program that executes in background, where all input data is avoided and output is saved in log files or similar.

This class lets to control the start and stop of the daemon programs and other commands related to the daemon too. It can see the status to check if it is running. Also lets to run the program in foreground to see any problem with code.

### Details

[](#details)

The program to be daemonized can be one of the following:

1. a function called once
2. a function called repeatedly in a loop
3. a function called once using system fork
4. a command line program running once with pcntl\_exec
5. a command line program running once with pcntl\_exec and fork
6. a command line program running in a loop with pcntl\_exec and fork

### Explanation

[](#explanation)

- system fork: it is a way to duplicate running process from the moment it is called, so it is possible to have two copies of the running program. It is used function pcntl\_fork().
- pcntl\_exec: when is used, the current running program is replaced by the command called.

The child processes can be called from an anonymous function, an existent function or using a php script.

### Example

[](#example)

Running a daemon task once

code:

```
