camspiers / pthreads-pool
Pool implementation for pthreads
Installs: 249
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/camspiers/pthreads-pool
Requires
- php: >=5.5.0
This package is auto-updated.
Last update: 2025-11-19 16:38:49 UTC
README
An implementation of a thread pool for pthreads
Example
namespace Camspiers\Pthreads;
require_once 'vendor/autoload.php';
class Job extends Work
{
protected function process()
{
// Do some work, and optionally return some data
return range(1, 1000);
}
}
$pool = new Pool();
for ($i = 0; $i < 1000; $i++) {
$pool->submitWork(new Job());
}
// get jobs as they finish
foreach ($pool->getFinishedJobs() as $job) {
var_dump($job->getData());
}
$pool->shutdown();
Working with an autoloader
In pthreads you need to register a autoload in each thread (or worker). The can be achieved by setting a loader
on the pool.
$loader = require 'vendor/autoload.php';
$pool = new \Camspiers\Pthreads\Pool();
$pool->setLoader($loader);
// Use the pool