Download the PHP package smwks/superprocess without Composer

On this page you can find all versions of the php package smwks/superprocess. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package superprocess

SuperProcess

+--------------------------------+
|                                |
|  >> SuperProcess               |
|                                |
|  [master] --+--> [worker]      |
|             +--> [worker]      |
|             +--> [worker]      |
|                                |
|  fork · supervise · scale      |
+--------------------------------+

A fluent PHP library for supervised master-child process control using pcntl and pipes. Run one or more copies of a command or PHP closure, keep them alive automatically, communicate with them via stdin/stdout and a structured IPC channel, and scale the pool up or down at runtime.

Two features define SuperProcess:

Requires PHP 8.4+, ext-pcntl, ext-posix — Linux and macOS only.


Installation


Quick start

Supervise a pool of command workers:

Fork a closure as a worker process:

Drive pool size from an external source via heartbeat:


Concepts

Command children

command(string $cmd) runs an external process for each child slot. The command is started with proc_open(), so it inherits PATH and environment variables. Each child gets four file descriptors:

fd direction purpose
0 — stdin master → child sendChildInput()
1 — stdout child → master onChildOutput()
2 — stderr child → master onChildOutput()
3 — IPC child → master onChildMessage() (JSON lines)

All pipes are non-blocking; reads happen inside the event loop via stream_select().

Closure children

closure(Closure $fn) forks the master with pcntl_fork() and runs the closure in the child. The closure receives a socket resource as its only argument — write JSON lines to it to send structured messages to the master via onChildMessage().

The closure captures its surrounding scope at the moment run() is called — that is when the fork actually happens. Any variable in scope at that point is available inside the child. Because the fork copies the master's entire memory image, expensive one-time work (bootstrapping a framework, parsing config, establishing a schema) is paid once in the master and shared copy-on-write across every worker.

Child lifecycle

On startup run() spawns min children. When a child exits:

  1. onChildExit fires with an ExitReason.
  2. If running count drops below min, a replacement is spawned with CreateReason::Replacement.

The master never exits the event loop on its own — send it SIGTERM or SIGINT (or call signal(posix_getpid(), ProcessSignal::Stop) from within a callback) to trigger a graceful shutdown.

Heartbeat

heartbeat(int $intervalSeconds, Closure $fn) registers a callback that fires on the master process at a regular interval throughout the event loop. The callback receives the live SuperProcess instance, giving it full runtime control.

This is the primary mechanism for externally-driven pool management. Instead of sizing the pool statically at startup, query whatever source of truth you have — a queue depth, a database flag, a config value — and nudge the pool toward the right size:

Because the heartbeat runs on the master — the process that owns the event loop — it is single-threaded and safe to call without locks. scaleUp() and scaleDown() each step by one and are no-ops when the pool is already at the configured limit.

Graceful shutdown

On SIGTERM or SIGINT (Ctrl+C) the master:

  1. Runs the onShutdown callback, if registered, while all children are still alive.
  2. Sends SIGTERM to every child.
  3. Waits up to 5 seconds for each to exit.
  4. Sends SIGKILL to any that remain.

The onShutdown callback is the right place to flush state, close connections, or send a final message to children before they are signalled:


API reference

Configuration

Callbacks

Runtime control

Enums and constants

Child properties


Sending structured messages from a command child

Write newline-delimited JSON to file descriptor 3. The master delivers each parsed line to onChildMessage.


Signals

Signal received by master Behaviour
SIGTERM Graceful shutdown — fires onShutdown, then drains children
SIGINT Graceful shutdown — same as SIGTERM (handles Ctrl+C)
SIGHUP Forwarded to all children
SIGCHLD Internal — triggers zombie reaping and pool replenishment
SIGUSR1 Fires onChildSignal for every running child
SIGUSR2 Fires onChildSignal for every running child

Development


SuperProcess is open-sourced under the MIT license.


All versions of superprocess with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2.0
ext-pcntl Version *
ext-posix Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package smwks/superprocess contains the following files

Loading the files please wait ...