2017 © Pedro Peláez
 

library react-thread-pool

Multiprocessing library for PHP based on pcntl_fork() and reactphp

image

rogerwaters/react-thread-pool

Multiprocessing library for PHP based on pcntl_fork() and reactphp

  • Thursday, June 9, 2016
  • by RogerWaters
  • Repository
  • 2 Watchers
  • 6 Stars
  • 12 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

react-thread-pool

This is a multiprocessing library for PHP based on pcntl_fork().

Status: alpha
Tests: none
, (*1)

Features

  • Running Parallel Processes out of a single Process
  • Give the entire environment to the Thread without thinking on serialisation
  • Control the thread (Start, Stop, Kill) + Custom messages
  • Running tons of threads on an single ThreadPool (be careful with your processor)
  • Setting up threads to observe external resources

Requirements

Basic Usage

Create an EventLoop:
, (*2)

$loop = ForkableFactory::create();

*The loop is the same as reactphp/event-loop so you can also use this for your server br/ Creating a default thread to perform heavy work outside your parent process:, (*3)

use RogerWaters\ReactThreads\EventLoop\ForkableLoopInterface;
use RogerWaters\ReactThreads\ThreadBase;

class ExampleThread extends ThreadBase
{
    protected function InitializeExternal(ForkableLoopInterface $loop)
    {
        //Do your external logic here
        //you can also use $loop functions
        //Use $this->kill(); to complete execution from child
        $this->kill();
    }
}

br/ All together:, (*4)

//create thread
$thread = new ExampleThread($loop);
//start thread and do external logic
$thread->start();

//wait for the thread to complete
$thread->on('stopped',function() use ($loop)
{
    //thread is done
    //stop the parent process
    $loop->stop();
});

//you can do any other operations here without affecting the thread

//run the loop to wait for completion
$loop->run();

For communicable threads see example_3.php and example_4.php, (*5)

More examples

See /examples folder, (*6)

TODO:

  • Documentation
  • Tests
  • More examples
  • https://github.com/reactphp/event-loop/issues/41
  • Stability / Error handling

If you have any issues or feature request, feel free to create a ticket, (*7)

The Versions

09/06 2016

dev-master

9999999-dev

Multiprocessing library for PHP based on pcntl_fork() and reactphp

  Sources   Download

MIT

The Requires