2017 © Pedro Peláez
 

library process

The process wrapper and manager based on pcntl and posix.

image

slince/process

The process wrapper and manager based on pcntl and posix.

  • Wednesday, August 23, 2017
  • by slince
  • Repository
  • 1 Watchers
  • 9 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 24 % Grown

The README.md

Process Library

Build Status Coverage Status Total Downloads Latest Stable Version Scrutinizer, (*1)

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

Installation

Install via composer, (*3)

composer require slince/process

Dependencies

The library replies on the following php's extension., (*4)

  • 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)

Usage

Basic usage

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

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:, (*5)

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

Shared memory

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

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

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

Semaphore

$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();
$queue->send('hello');
echo $queue->receive(); //Will output hello

Fifo

$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();

License

The MIT license. See MIT, (*7)

The Versions

23/08 2017

dev-master

9999999-dev

The process wrapper and manager based on pcntl and posix.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by tao

process pipe pcntl fork posix semaphore shared memory child process fifo system v

28/04 2017

1.0.0

1.0.0.0

The process wrapper and manager based on pcntl and posix.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by tao

process pipe pcntl fork posix semaphore shared memory child process system v