Download the PHP package stephanschuler/fork-job-runner without Composer
On this page you can find all versions of the php package stephanschuler/fork-job-runner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fork-job-runner
Fork Job Runner
Creating child processes is expensive, especially when this comes with bootstrapping huge parts of a framework.
This package constantly holds a single PHP process at a certain bootstrap level and forks this process whenever a job is to be executed.
All the demo code blow is to be implemented by the project, it is not provided by this package.
This package does not aim for parallel processing. This might work but other libraries or frameworks like e.g. ReactPHP are way better suited for this.
The primary objective is providing a technical basis for message queues in functional tests. There is specifically the Flowpack Jobqueue Common package shipping a Fake Queue where this package is meant to help providing a replacement.
Jobs
Every code that should be run in a separate process is called a Job
. Jobs are
created by the parent, serialized, passed to the worker child and unserialized
prior to execution. This needs to be considered, especially when dealing with
database connections, file pointers and other resources.
The Job
is a regular class definition. Put it in your project where it can be
found by the autoloader.
Dispatching
Passing a job from the parent process to isolated execution is called dispatching. There is no routing mechanism to hand jobs to different works nor is it this packages intention to execute jobs asynchronously or in parallel.
Creating the dispatcher should be done only once because each dispatcher keeps its own worker process around.
Dispatching should be done wherever needed, e.g. within action methods in MVC controllers or in test methods of unit tests.
The Loop
The Loop
is the child process waiting for the incoming Job
. The Dispatcher
initializes the Loop
and passes Job
s along.
This is meant to be a CLI entry point. It's the "loop.php" file mentioned in the
example code of the Dispatcher
.
The Loop::run()
method does never return unless the dispatchers command stream
is open.
Responding
Jobs can respond to the dispatching process. Every serializable data can be
passed from Job
to Dispatcher
.
All versions of fork-job-runner with dependencies
ext-pcntl Version *
ext-posix Version *