<?php
/*
* Homepage http://netkiller.github.io
* Author: netkiller*/
class ExampleWorker extends Worker {
public function __construct(Logging $logger) {
$this->logger = $logger;
}
protected $logger;
}
/* the collectable class implements machinery for Pool::collect */
class Work extends Stackable {
public function __construct($number) {
$this->number = $number;
}
public function run() {
$this->worker
->logger
->log("%s executing in Thread #%lu",
__CLASS__, $this->worker->getThreadId());
sleep(1);
printf("runtime: %s, %d\n", date('Y-m-d H:i:s'), $this->number);
$this->status = "OK";
}
}
class Logging extends Stackable {
protected function log($message, $args = []) {
$args = func_get_args();
if (($message = array_shift($args))) {
echo vsprintf("{$message}\n", $args);
}
}
}
$pool = new Pool(5, \ExampleWorker::class, [new Logging()]);
foreach (range(0, 100) as $number) {
$pool->submit(new Work($number));
}
$pool->shutdown();
var_dump($pool);
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号