wulsic / parallel-pool
使用并行实现的一个类似于 PThreads 池的实现。
1.0.4
2020-12-09 10:13 UTC
Requires
- php: >=7.2
README
此库在新的 Parallel 库的帮助下提供类似于 PThreads Pool 的功能。
示例用法
<?php require_once __DIR__ . '/vendor/autoload.php'; $workers = 10; $jobs = 1000; $pool = new \Wulsic\Pool\Pool($workers); echo "Worker count: $workers" . PHP_EOL; $start = microtime(true); for($i = 0; $i < $jobs; $i++) { echo "Job $i" . PHP_EOL; $pool->submit( function ($taskId) { print "Active task: $taskId" . PHP_EOL; return "Finished task: $taskId"; }, [$i] ); } while($pool->collect()) { continue; } $pool->shutdown(); printf( "Finished %s threads in %.2f seconds\n", $workers ? "with {$workers}" : "without", microtime(true) - $start );
许可证
本包所有内容均受 [MIT 许可证] 许可。