Download the PHP package misterion/ko-process without Composer
On this page you can find all versions of the php package misterion/ko-process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download misterion/ko-process
More information about misterion/ko-process
Files in misterion/ko-process
Package ko-process
Short Description Simple pcntl fork wrapper and process manager
License MIT
Homepage https://github.com/misterion/ko-process
Informations about the package ko-process
ko-process
Ko-Process allows for easy callable forking. It is object-oriented wrapper around fork part of
PCNTL
PHP's extension. Background process, detaching process from the
controlling terminal, signals and exit codes and simple IPC via shared memory. This is well tested library used in
real world high load projects.
Installation
Requirements
PHP >= 5.4
pcntl extension installed
posix extension installed
Via Composer
The recommended way to install library is composer. You can see package information on Packagist.
Do not use composer?
Just clone the repository and care about autoload for namespace Ko
.
Usage
Basic usage looks like this:
If should wait for all forked process
Process title?
Yes, both ProcessManager
and Process
can change process title with setProcessTitle
function. Or you may use trait
Ko\Mixin\ProcessTitle to add this to any class you want. Take attention about ProcessManager::onShutdown
- use can
set callable which would be called if ProcessManager
catch SIGTERM
. The handler would be called before child process
would be shutdown. We use demonize
to detach from terminal. Run sample with code
and ps aux|grep I_am_a_master
or top
to see you process title in linux process list.
Spawn
Making master - child process pattern application you should care about child process be alive. The spawn
function
will help you with that - once spawn
will keep forked process alive after he exit with some error code.
Let`s explain you are writing something like queue worker based on PhpAmqpLib\AMPQ. So you can write something like this
Shared memory and Semaphore
The Ko\SharedMemory
used Semaphore
for internal locks so can be safely used for inter process communications.
SharedMemory implements \ArrayAccess
and \Countable
interface so accessible like an array:
You can use Semaphore
for inter process locking:
Credits
Ko-process written as a part of GameNet project by Nikolay Bondarenko (misterionkell at gmail.com).
License
Released under the MIT license.