The process wrapper and manager based on pcntl and posix.

1.0.0 2017-04-28 08:25 UTC

This package is auto-updated.

Last update: 2024-02-13 16:23:59 UTC


Build Status Coverage Status Total Downloads Latest Stable Version Scrutinizer

The library help to work with processes. It provides a more readable api and various modes for IPC via pipe(FIFO) and system v.


Install via composer

composer require slince/process


The library replies on the following php's extension.

  • ext-pcntl. Provides control processes (MUST)
  • ext-sysvshm. Porvides system v shared memory (OPTIONAL)
  • ext-sysvsem. Porvides system v semaphore (OPTIONAL)
  • ext-sysmsg. Porvides system v message queue (OPTIONAL)


Basic usage

$process = new Slince\Process\Process(function(){
    echo 'hello, my pid is ' . getmypid();

var_dump($process->isRunning()); // echo true
var_dump($process->getPid()); // will output the pid of child process
//do something other

$process->wait(); //waiting for the process to exit 

Sends signal to the process

Note: If your php version is less than 7.1, please add the statement declare(ticks=1); at the beginning of the file:

$process = new Slince\Process\Process(function(){
    Slince\Process\Process::current()->signal([SIGUSR1, SIGUSR2], function(){
        echo 'trigger signal';
    echo 'hello, my pid is ' . getmypid();
//do something

Shared memory

$memory = new Slince\Process\SystemV\SharedMemory();
$memory->set('foo', 'bar');

The default size of shared memory is the sysvshm.init_mem in the php.ini, otherwise 10000 bytes. You can adjust this.

$memory = new Slince\Process\SystemV\SharedMemory(__FILE__, '5M'); //Adjusts to 5m


$semaphore = new Slince\Process\SystemV\Semaphore();
$semaphore->acquire(); //Acquires a lock
// do something
$semaphore->release() //Releases a lock

Message queue

$queue  = new Slince\Process\SystemV\MessageQueue();
echo $queue->receive(); //Will output hello


$writeFifo = new Slince\Process\Pipe\WritableFifo('/tmp/test.pipe');
$writeFifo->write('some message');
$readFifo = new Slince\Process\Pipe\ReadableFifo('/tmp/test.pipe');
echo $readFifo->read();


The MIT license. See MIT