Git Product home page Git Product logo

process's Introduction

Process Library

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.

Installation

Install via composer

composer require slince/process

Dependencies

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)

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:

$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.

$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

process's People

Contributors

slince avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.