PHP code example of white-rabbit-1-sketch / php-worker-pool
1. Go to this page and download the library: Download white-rabbit-1-sketch/php-worker-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/ */
white-rabbit-1-sketch / php-worker-pool example snippets
use PhpWorkerPool\ClosureTask;
use PhpWorkerPool\Pool;
use PhpWorkerPool\Queue\SysVQueue;
0; $i++) {
$queue->push(new ClosureTask(function () {
echo microtime() . PHP_EOL;
sleep(1);
}));
}
$pool->wait();
$pool->stop();
use PhpWorkerPool\ClosureTask;
use PhpWorkerPool\Pool;
use PhpWorkerPool\Queue\RedisQueue;
use Predis\Client as RedisClient;
t();
$queue = new RedisQueue($redisClient, "test-queue", 123);
$pool = new Pool($queue);
$pool->start();
for ($i = 0; $i < 20; $i++) {
$queue->push(new ClosureTask(function () {
echo microtime() . PHP_EOL;
sleep(1);
}));
}
$pool->wait();
$pool->stop();
use PhpWorkerPool\ClosureTask;
use PhpWorkerPool\Pool;
use PhpWorkerPool\Queue\SysVQueue;
20; $i++) {
$queue->push(new ClosureTask(function () {
echo microtime() . PHP_EOL;
sleep(1);
}));
}
$pool->start();
$pool->wait();
$pool->stop();
use PhpWorkerPool\ClosureTask;
use PhpWorkerPool\Pool;
use PhpWorkerPool\Queue\RedisQueue;
use Predis\Client as RedisClient;
t();
$queue = new RedisQueue($redisClient, "test-queue", 123);
$pool = new Pool($queue, infinite: false);
for ($i = 0; $i < 20; $i++) {
$queue->push(new ClosureTask(function () {
echo microtime() . PHP_EOL;
sleep(1);
}));
}
$pool->start();
$pool->wait();
$pool->stop();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.