Download the PHP package flytachi/winter-thread without Composer
On this page you can find all versions of the php package flytachi/winter-thread. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flytachi/winter-thread
More information about flytachi/winter-thread
Files in flytachi/winter-thread
Package winter-thread
Short Description A lightweight process engine for PHP — Java-like control of background tasks as isolated OS processes, without heavy extensions (no swoole/pthreads/parallel).
License MIT
Homepage https://winterframe.net
Informations about the package winter-thread
Winter Thread: A Modern Process Control Library for PHP
Winter Thread is a process engine for PHP: a clean, object-oriented, Java-like API for running and controlling background tasks as isolated OS processes — for parallel and long-running work.
It's an engine — the foundation you build on. A small, dependable core, not a batteries-included framework: the layer your queues, pools, schedulers and workers sit on top of. You bring the higher-level concurrency; the engine handles the hard, boring parts — spawning, signals, isolation, transports.
A
Threadhere is a process, not a PHP thread. The name is a deliberate nod to a familiar API — just as Python'smultiprocessing.Processmirrors its threading interface. EveryThreadis one fully isolated OS process wearing a clean, thread-like face (start(),join(),isAlive()) — so there's no shared state to corrupt and nothing to leak between tasks.
No heavy extensions. Unlike pthreads, ext-parallel, or Swoole, it needs
no ZTS build and no exotic runtime — just proc_open and the standard POSIX
extensions (ext-pcntl, ext-posix) that ship with nearly every PHP install.
Each task runs in a fresh, isolated PHP process, so there is no shared state to
corrupt and no inherited connections to break.
Key Features
- No heavy extensions: No swoole / parallel / pthreads, no ZTS build — just
proc_open+ standard POSIX. Runs on a normal PHP install. - Clean process isolation: Each task runs in a brand-new PHP process — no inherited DB connections, sockets, or global state to corrupt.
- Fluent, Object-Oriented API: Manage background processes as objects.
- Full Process Control:
start(),join(),pause(),resume(),terminate(), andkill(). - Advanced Process Naming: Identify your processes easily with namespaces, names, and tags.
- Safe by Default: Output goes to
/dev/nullby default — no Broken pipe risk for fire-and-forget jobs. - Swoole / Event-Loop Compatible: Launch background tasks from inside a coroutine safely — the default
AdaptiveLauncherroutes to a Swoole-native backend (Coroutine\System::exec) whereproc_openwould corrupt the reactor's fds, with pipe-free payload transports (temp-file, shared-memory). Noext-swoolerequired; it's used only when present. - Zombie-free fire-and-forget: Optional detached mode (
fork+setsid) reparents workers to init, so long-lived parents (FPM, daemons) never accumulate zombies. - Pluggable backend: Swap the payload transport or the whole spawn strategy through a single
Launcher— build custom backends (Docker, SSH, …) without touchingThread. - Java-like API: Familiar method names like
isAlive()andjoin()for an easy learning curve.
Requirements
- PHP >= 8.4
ext-pcntlext-posixopis/closure^4.5 (required; enables safe serialization of anonymous classes and closures)ext-shmop(optional; only for the shared-memory transport)
Installation
Quick Start
Configuration — the Launcher
Configuration goes through a single Launcher, bound once at bootstrap with
Thread::bindLauncher(). When you bind nothing, a self-configuring AdaptiveLauncher
is used (AdaptiveLauncher::adaptive()), which routes each launch to the right
backend for the current runtime — CliLauncher on CLI / FPM, SwooleLauncher
inside a Swoole coroutine.
Swoole / Event-Loop Compatibility
When its transport is left unset, the launcher picks a pipe-free transport
(TempFileTransport) if it detects an active Swoole runtime — pipe file
descriptors from proc_open do not survive SWOOLE_HOOK_ALL intact.
Launching from inside a Swoole coroutine is supported. A pipe-free transport handles the payload, but the spawn is the other half: native
proc_opencontends with the reactor over the file-descriptor table from inside a coroutine. The defaultAdaptiveLaunchercloses that gap — it routes toSwooleLauncher, which starts the runner as a shell background job (Coroutine\System::exec()) that never touches the reactor's fds. So in-coroutine dispatch works out of the box; plain CLI and FPM go throughproc_openexactly as before. See docs/07.
| Transport | Delivery | Parent pipe fd | Requires |
|---|---|---|---|
PipeTransport |
stdin pipe (default in CLI) | yes | — |
TempFileTransport |
temp file as stdin | none | — |
ShmTransport |
shared memory | none | ext-shmop |
Detached (zombie-free) fire-and-forget
For a long-lived parent (FPM worker, daemon) that dispatches background tasks and never
joins them, pass detached: true. The launcher exits immediately and the real worker is
reparented to init (pid 1), so no zombie ever accumulates under the parent:
Signal control still works via the worker's self-reported PID (write getmypid() from
inside the task to your own store), since the engine's control model is PID-based.
Output Modes
$outputTarget |
Use case |
|---|---|
'/dev/null' (default) |
Fire-and-forget: safe, output discarded |
'/path/to/file.log' |
Persistent logging for staging/production |
null (explicit) |
Piped to parent: read via readOutput() / readError() |
Note: With
null,join()andreap()drain the pipes internally while they wait, so a barejoin()never deadlocks on a large output — andreadOutput()after it returns the full buffered output. Use an explicitreadOutput()poll loop only when you want the output live as it is produced.
Process Control
Running Tests
Tests come in two tiers (mirroring the winter-kernel layout):
Default — runs on any machine; unsupported extensions self-skip:
Containered — heavy, environment-specific checks (leak / timing / nested / battle-run, with Cli / FPM / Swoole), run inside Docker across a list of PHP versions:
CI (.github/workflows/ci.yml) runs the default suite via setup-php and the container
suite via the bundled tests/docker/Dockerfile, on a PHP 8.4 / 8.5 matrix.
Documentation
Full documentation lives in /docs:
- Introduction — philosophy, the no-heavy-ext story, when to use it
- Installation & Requirements
- Quickstart — a complete parallel example in 5 minutes
- Basic Usage
- Output & Debugging
- Process Control & Lifecycle — signals, graceful shutdown
- The Launcher
- Payload Transports
- Detached Mode
- Security
- Architecture & Internals
- Patterns — pools, returning results, retries
- Troubleshooting
- API Reference
- Testing
Contributing
Contributions are welcome! Please submit a pull request or open an issue for bugs, questions, or feature requests.
License
This library is open-source software licensed under the MIT license.