dev-master
9999999-devMultiprocessing library for PHP based on pcntl_fork() and reactphp
MIT
The Requires
Wallogit.com
2017 © Pedro Peláez
Multiprocessing library for PHP based on pcntl_fork() and reactphp
This is a multiprocessing library for PHP based on pcntl_fork().
Status: alpha
Tests: none
, (*1)
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)
See /examples folder, (*6)
If you have any issues or feature request, feel free to create a ticket, (*7)
Multiprocessing library for PHP based on pcntl_fork() and reactphp
MIT