PHP code example of netlogix / jobqueue-pool

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
        });
    });



use Netlogix\JobQueue\Pool\Pool;

Pool::create(outputResults: true)
    ->runLoop(function(Pool $pool) {
        $process = $pool->runJob($job);
        $process->on('exit', fn() => $pool->eventLoop->stop());
    });


use Netlogix\JobQueue\Pool\Pool;

Pool::create(outputResults: false)
    ->runLoop(function(Pool $pool) {
        $process = $pool->runJob($job);
        $process->stdout->on('data', fn($chunk) => fputs(\STDOUT, $chunk));
        $process->stderr->on('data', fn($chunk) => fputs(\STDOUT, $chunk));
        $process->on('exit', fn() => $pool->eventLoop->stop());
    });


use Netlogix\JobQueue\Pool\Pool;

Pool::create(async: true)
    ->runLoop(function(Pool $pool) {
        $pool->runJob($job);
    });


use Netlogix\JobQueue\Pool\Pool;

Pool::create(preforkSize: 3)
    ->runLoop();


use Netlogix\JobQueue\Pool\Pool;

$loop = \React\EventLoop\Loop::get();

Pool::create(eventLoop: $loop)
    ->runLoop();