1. Go to this page and download the library: Download netlogix/jobqueue-pool 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/ */
netlogix / jobqueue-pool example snippets
use Netlogix\JobQueue\Pool\Pool;
Pool::create(
outputResults: true,
async: false,
preforkSize: 1
)
->runLoop(function(Pool $pool) {
$process = $pool->runJob(new VeryLongRunningJob());
$process->on('success', function(int $exitCode) {
echo 'success' . PHP_EOL;
});
$process->on('error', function(int $exitCode, $errorMessageStream) {
echo 'failed: ' . $exitCode . PHP_EOL;
echo stream_get_contents($errorMessageStream);
});
$process->on('exit', function() use ($pool) {
if (count($pool) === 0) {
$pool->eventLoop->stop();
}
});
$pool->eventLoop->addTimer(5, function() use ($process) {
$process->stdin->write('hello!' . PHP_EOL);
});
$pool->eventLoop->addPeriodicTimer(function() {
// ping parent database connections while children are working
});
});