本文整理汇总了PHP中Pool类的典型用法代码示例。如果您正苦于以下问题:PHP Pool类的具体用法?PHP Pool怎么用?PHP Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: workerPool
/**
* worker master - Pool
*/
function workerPool()
{
$start = microtime(true);
echo "\nworker start at {$start}";
$jobs = array();
if ($jobs) {
$wNum = 5;
//进程数
$jobCnt = count($jobs);
$w = ceil($jobCnt / $wNum);
//
$pool = new Pool("demoWorker", $w);
$pool->addJobs($jobs);
$pool->waiting();
$stop = microtime(true);
$cost = $stop - $start;
echo "\nworker {$jobCnt} jobs done at {$stop}";
echo "\nworker cost time = {$cost}";
} else {
//for daemon mode
echo "\nworker no job and sleep 5s";
sleep(5);
}
$end = microtime(true);
echo "\nworker end at {$end}";
}
示例2: assertHit
protected function assertHit($expected, Pool $pool, $key)
{
$this->assertEquals($expected, $pool->get($key));
$this->assertEquals($expected, $pool->getItem($key)->get());
$this->assertTrue($pool->getItem($key)->isHit());
$this->assertTrue($pool->hasItem($key));
}
示例3: onReady
/**
* Called when the worker is ready to go
* @return void
*/
public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$this->redis->multi(function ($multi) {
// "OK"
D('start multi: ' . $multi->result);
$multi->set('test1', 'value1', function ($redis) use($multi) {
// "QUEUED"
D('in multi 1: ' . $redis->result);
$this->redis->set('test1', 'value1-new', function ($redis) {
// "OK", not "QUEUED"
D('out multi 1: ' . $redis->result);
});
setTimeout(function ($timer) use($multi) {
// "QUEUED"
$multi->set('test2', 'value2', function ($redis) use($multi) {
D('in multi 2: ' . $redis->result);
$multi->exec(function ($redis) {
D('exec');
D($redis->result);
});
});
$timer->free();
}, 200000.0);
});
});
}
示例4: testPoolGc
public function testPoolGc()
{
$pool = new Pool(1, PoolTestWorker::class, [new stdClass(), new Threaded()]);
$work = new PoolTestWork();
$pool->submit($work);
while (@$i++ < 2) {
$pool->submit(new PoolTestWork());
# nothing to assert, no exceptions please
}
$pool->submitTo(0, new PoolTestWork());
# nothing to assert, no exceptions please
/* synchronize with pool */
$sync = new PoolTestSync();
$pool->submit($sync);
$sync->synchronized(function ($sync) {
if (!$sync->finished) {
$sync->wait();
}
}, $sync);
$pool->collect(function ($task) {
$this->assertTrue($task->isGarbage());
return true;
});
$pool->shutdown();
}
示例5: useMultiCore1
public function useMultiCore1()
{
$core = $this->getCoreCount();
$pool = new \Pool($core);
for ($i = 0; $i < $core; $i++) {
$pool->submit(new ProveWorker());
}
}
示例6: fetchAdjustments
/**
* @param string[] $adjustments
* @return AdjustmentInterface[]
*/
protected function fetchAdjustments($adjustments)
{
$instances = [];
foreach ($adjustments as $code) {
$instances[$code] = $this->adjustmentPool->getAdjustmentByCode($code);
}
uasort($instances, [$this, 'sortAdjustments']);
return $instances;
}
示例7: allAction
function allAction()
{
$order = addslashes(trim($this->_request->getParam('order', 'Name')));
$this->view->title = $this->view->translate->_("Pools");
// to view
$this->view->meta_refresh = 300;
// meta http-equiv="refresh"
$pools = new Pool();
$this->view->pools = $pools->fetchAll(null, $order);
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$pool = new \Pool($input->getOption('threads'), \Worker::class);
foreach ($input->getArgument('indexes') as $index) {
$pool->submit(new IndexerRunner($input->getOption('indexer'), $input->getOption('config'), $index));
}
$pool->shutdown();
$pool->collect(function (IndexerRunner $work) use($output) {
$output->writeln($work->return);
});
}
示例9: __construct
public function __construct($threadSayisi, BurtayThread $sinif)
{
$pool = new Pool($threadSayisi);
$is_listesi = array();
for ($i = 1; $i <= $threadSayisi; $i++) {
$is_listesi[] = new burtayThreadPool($sinif);
}
foreach ($is_listesi as $liste) {
$pool->submit($liste);
}
$pool->shutdown();
}
示例10: shuffleTillMatch
/**
* @param Pool $pool
*
* @return array|bool
*/
private function shuffleTillMatch(Pool $pool)
{
$timeToStop = microtime(true) + self::SHUFFLE_TIME_LIMIT;
$entries = $pool->getEntries()->getValues();
while (microtime(true) < $timeToStop) {
$set = $this->shuffleArray($entries);
if ($this->checkValidMatch($entries, $set)) {
$this->matchedExcludes = $set;
return $set;
}
}
return false;
}
示例11: testUnsubscribeAll
public function testUnsubscribeAll()
{
$pool = new Pool();
$mockEvent1 = $this->getMockBuilder('Athrois\\Event')->getMock();
$mockEvent2 = $this->getMockBuilder('AnotherEvent')->getMock();
$mockListener = $this->getMockBuilder('Athrois\\Listener')->getMock();
$identifier1 = Pool::getId($mockEvent1);
$identifier2 = Pool::getId($mockEvent2);
$pool->register($mockListener, $identifier1);
$pool->register($mockListener, $identifier2);
$pool->unsubscribe($mockListener);
$this->assertAttributeEquals(array(), 'listeners', $pool);
}
示例12: onReady
/**
* Called when the worker is ready to go.
* @return void
*/
public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
/*$this->redis->eval("return {'a','b','c', {'d','e','f', {'g','h','i'}} }",0, function($redis) {
Daemon::log(Debug::dump($redis->result));
});*/
$this->redis->subscribe('te3st', function ($redis) {
Daemon::log(Debug::dump($redis->result));
});
$this->redis->psubscribe('test*', function ($redis) {
Daemon::log(Debug::dump($redis->result));
});
}
示例13: setPool
public function setPool()
{
$pool = new Pool();
foreach ($this->getConfiguration() as $key => $value) {
$array = new ArrayObject($value);
$server = new Server();
$server->setHost($array->offsetGet(self::SERVER_PROPERTY_HOST))->setPort($array->offsetGet(self::SERVER_PROPERTY_PORT))->setName($key);
if ($array->offsetExists(self::SERVER_PROPERTY_AUTH)) {
$server->setAuth($array->offsetGet(self::SERVER_PROPERTY_AUTH));
}
$pool->attach($server);
}
$this->pool = $pool;
}
示例14: mainThreadHeartbeat
/**
* @param int $currentTick
*/
public function mainThreadHeartbeat($currentTick)
{
$this->currentTick = $currentTick;
while ($this->isReady($this->currentTick)) {
/** @var TaskHandler $task */
$task = $this->queue->extract();
if ($task->isCancelled()) {
unset($this->tasks[$task->getTaskId()]);
continue;
} else {
$task->timings->startTiming();
$task->run($this->currentTick);
$task->timings->stopTiming();
}
if ($task->isRepeating()) {
$task->setNextRun($this->currentTick + $task->getPeriod());
$this->queue->insert($task, $this->currentTick + $task->getPeriod());
} else {
$task->remove();
unset($this->tasks[$task->getTaskId()]);
}
}
if ($this->asyncTasks > 0) {
//Garbage collector
$this->asyncPool->collect([$this, "collectAsyncTask"]);
foreach ($this->asyncTaskStorage as $asyncTask) {
if ($asyncTask->isFinished() and !$asyncTask->isCompleted()) {
$this->collectAsyncTask($asyncTask);
}
}
}
}
示例15: testPool
private function testPool()
{
$initTime = microtime(true);
$pool = new \Pool(8, \Worker::class);
for ($i = 0; $i < 10; $i++) {
$pool->submit(new Work());
}
$initTime = microtime(true) - $initTime;
$finishTime = microtime(true);
$pool->shutdown();
$pool->collect(function (Work $work) {
echo 'Work of ', get_class($work), ' #', $work->i, ' - ', $work->getWork(), PHP_EOL;
});
$finishTime = microtime(true) - $finishTime;
return [$initTime, $finishTime];
}