1. Go to this page and download the library: Download toalett/multiprocessing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
toalett / multiprocessing example snippets
use Toalett\Multiprocessing\ContextBuilder;
$builder = ContextBuilder::create();
$context = $builder->build();
use Toalett\Multiprocessing\ContextBuilder;
$context = ContextBuilder::create()->build();
$job = static function(string $name) {
print("Hello from {$name}!\n");
usleep(500_000);
print("Goodbye from ${name}!\n");
};
$context->submit($job, 'John Snow');
use Toalett\Multiprocessing\Concurrency;
use Toalett\Multiprocessing\ContextBuilder;
$context = ContextBuilder::create()
->withConcurrency(Concurrency::atMost(2))
->build();
// $job = function(...)...
foreach(['John', 'Stannis', 'Jorah', 'Robert', 'Daario'] as $name) {
$context->submit($job, $name);
}
$context->run();
use React\EventLoop\Factory;
use Toalett\Multiprocessing\ContextBuilder;
$loop = Factory::create();
$context = ContextBuilder::create()
->withEventLoop($loop)
->build();
// Submit a job every 5 seconds
$loop->addPeriodicTimer(5.0, fn() => $context->submit(...));
$context->run();