{"id":36253424,"url":"https://github.com/lifo101/php-daemon","last_synced_at":"2026-01-11T07:03:14.612Z","repository":{"id":62517076,"uuid":"92170959","full_name":"lifo101/php-daemon","owner":"lifo101","description":"PHP Multiprocessing Daemon. Easily create stable and robust daemons with minimal boilerplate code.","archived":false,"fork":false,"pushed_at":"2025-03-04T13:37:01.000Z","size":213,"stargazers_count":50,"open_issues_count":0,"forks_count":15,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-10-01T13:46:58.303Z","etag":null,"topics":["daemon","php-daemon","php-library","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lifo101.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-23T12:35:37.000Z","updated_at":"2025-08-22T11:14:41.000Z","dependencies_parsed_at":"2023-02-01T09:31:53.504Z","dependency_job_id":null,"html_url":"https://github.com/lifo101/php-daemon","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/lifo101/php-daemon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifo101%2Fphp-daemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifo101%2Fphp-daemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifo101%2Fphp-daemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifo101%2Fphp-daemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lifo101","download_url":"https://codeload.github.com/lifo101/php-daemon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifo101%2Fphp-daemon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28296941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T04:44:51.577Z","status":"ssl_error","status_checked_at":"2026-01-11T04:44:44.232Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["daemon","php-daemon","php-library","symfony"],"created_at":"2026-01-11T07:03:14.525Z","updated_at":"2026-01-11T07:03:14.597Z","avatar_url":"https://github.com/lifo101.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PHP Daemon Library\n\n### Synopsis\nCreate robust and stable PHP multiprocess daemons without the boilerplate code. The core [Daemon](../../wiki/Daemon) \nclass handles the main loop and events and can run at any frequency desired _(within the limits of PHP)_. You only have\nto implement a single method `execute` to run a daemon process, optionally in the background.\n\nUsing [Tasks](../../wiki/Tasks) and [Workers](../../wiki/Workers) the daemon can call methods on background processes \nseamlessly w/o worrying about managing forked children. [Plugins](../../wiki/Plugins) allow you to easily create \nreusable and shareable code for your Daemons. See the [Features](#features) section below for more information.\n\n### Why write a daemon in PHP?\nObviously, writing robust, stable and long-running daemons in PHP is generally not a good idea. It's at least very\nhard to do, and do well. I personally needed a daemon in PHP because I had an entire website framework built in Symfony\nthat needed a major back-end daemon. I wanted to be able to re-use all my front-end dependencies and entities w/o \nduplicating resources or configs.\n\nWhile this library does everything it can to allow you to create a rock solid daemon, care must still be taken in your \nuser-land code to keep things stable. \n\n### Requirements\n- PHP ^7.4 || ^8.0 _(for PHP ^5.4 use the ^1.0 tag and branch)_\n- A POSIX compatible operating system (Linux, OSX, BSD)\n- PHP [POSIX](http://php.net/posix) and [PCNTL](http://php.net/pcntl) Extensions\n\n### Documentation\nSee the [Wiki](../../wiki) for documentation.\n\n### Examples\nSee the [examples](examples) directory for examples you can run. \n\n### Features\n- The `Main Loop` is maintained by the core [Daemon](../../wiki/Daemon) class. All you have to do is implement one \n  method `execute` that will get called every loop cycle. The loop frequency can be any fractional value in seconds. \n  If set to 0, your `execute` method will get called as fast as possible (_not normally recommended, unless your loop \n  is doing some sort of blocking call, ie: listening on a socket, etc_).\n- In just a few lines of code you can have parallel processes running in the background. \n  - A [Task](../../wiki/Tasks) allows you to call any method or callback in a background process. No communication is \n    made between the background process and the parent. \n    Tasks are meant for simple things, for example: Sending an email.\n  - A [Worker](../../wiki/Workers) allows you to call any method on an object, or even just a simple callback like a \n    [Task](../../wiki/Tasks). Workers can return a value back to the parent via a simple `return` statement in your \n    worker method(s). Workers are maintained automatically and can have multiple children running at the same time, \n    which is handled transparently. Even if a worker dies or is killed by the OS the Daemon API will still return a \n    result (or exception) to your code. The return value of a Worker is usually a `Promise` object. You can use the \n    standard Promise methods like `then` or `otherwise` to act on the return value. Or you can register an `ON_RETURN` \n    callback on the Worker.\n    \n    Workers use a [Mediator design pattern](https://en.wikipedia.org/wiki/Mediator_pattern) and use Shared Memory\n    for it's messaging queue and data. Different IPC classes can be created to provide alternate communication methods\n    between the parent and children. _I might work on a second IPC class that uses sockets instead of SHM to provide\n    an alternate choice_.\n- Event Handling. The core `Daemon` has several events (see: [Events](../../wiki/Events))\n  that you can easily interface with by registering a callback. Some events have the means to change the behavior of \n  the daemon.\n- Easy Signal Handling via the Event Dispatcher. To catch a signal you simply have to register a `ON_SIGNAL` callback \n  in your code. Your callback will be passed an `SignalEvent` with the signal that was caught.\n- Simple `Plugin` architecture allows you to use and create your own plugins that can be injected into the Daemon. \n  Plugins can be lazily loaded.\n  - A core plugin `FileLock` allows you to add a locking mechanism to prevent your daemon from running more than one\n    instance at a time. Simply register the plugin in your daemon and the rest is automatic. A `ShmLock` is similar\n    but uses Shared Memory to obtain a lock.\n- Automatic restarting. The Daemon can automatically restart itself if it's runtime reached a configurable threshold \n  or if a fatal error occurred. \n- Built in logging. The `Daemon` has 3 basic logging methods: `log`, `error`, `debug`. All of these will write to the\n  log file (if configured). If the log file is rotated, overwritten or deleted, the daemon will automatically detect \n  this and will continue to write to the new log file. The [DaemonEvent::ON_LOG](../../wiki/Events#on_log) event allows \n  you to register a callback to change the behavior too. User code can use the [LogTrait](../../wiki/Logging) to easily \n  add native daemon logging to their code.\n\n### Credit\nThe basis for this library was inspired by the [PHP-Daemon](https://github.com/shaneharter/PHP-Daemon) library\nfrom [Shane Harter](https://github.com/shaneharter) on GitHub. Unfortunately, his library was abandoned (or is on \nindefinite hiatus), was written for PHP v5.3, had no namespacing, no package management or an auto-loader (ie: Composer). \n\nI choose to create an entirely new library instead of forking and modifying his original library for educational \npurposes. I also didn't agree with some of his methodologies. I do require some extra dependencies, but \n[Composer](http://getcomposer.org/) makes this a trivial issue.\n\n---\n_This library is in a fully working state. I've created very complex daemons that have run for months w/o any memory \n leaks or crashes. More could be done...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifo101%2Fphp-daemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flifo101%2Fphp-daemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifo101%2Fphp-daemon/lists"}