本文整理汇总了PHP中Pool类的典型用法代码示例。如果您正苦于以下问题:PHP Pool类的具体用法?PHP Pool怎么用?PHP Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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}";
}
开发者ID:shaogx,项目名称:easyJob,代码行数:29,代码来源:demo.php
示例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));
}
开发者ID:jivoo,项目名称:jivoo,代码行数:7,代码来源:PoolTest.php
示例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);
});
});
}
开发者ID:kakserpom,项目名称:phpdaemon,代码行数:31,代码来源:Multi.php
示例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();
}
开发者ID:krakjoe,项目名称:pthreads-polyfill,代码行数:25,代码来源:PoolTest.php
示例5: useMultiCore1
public function useMultiCore1()
{
$core = $this->getCoreCount();
$pool = new \Pool($core);
for ($i = 0; $i < $core; $i++) {
$pool->submit(new ProveWorker());
}
}
开发者ID:organization,项目名称:SpawningPool,代码行数:8,代码来源:Prove.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:Collection.php
示例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);
}
开发者ID:staser,项目名称:webacula,代码行数:10,代码来源:PoolController.php
示例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);
});
}
开发者ID:borro,项目名称:sphinx_indexer,代码行数:11,代码来源:IndexCommand.php
示例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();
}
开发者ID:burtay,项目名称:ThreadPool.php,代码行数:12,代码来源:ThreadPool.php
示例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;
}
开发者ID:pix-art,项目名称:SecretSanta,代码行数:18,代码来源:EntryShuffler.php
示例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);
}
开发者ID:drx777,项目名称:athrois,代码行数:13,代码来源:PoolTest.php
示例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));
});
}
开发者ID:cobolbaby,项目名称:phpdaemon,代码行数:17,代码来源:Simple.php
示例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;
}
开发者ID:tin-cat,项目名称:redis-info,代码行数:14,代码来源:Config.php
示例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);
}
}
}
}
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:35,代码来源:ServerScheduler.php
示例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];
}
开发者ID:borro,项目名称:tests,代码行数:16,代码来源:PThreadsCommand.php
示例16: definePool
public function definePool($name, $num = null)
{
$parts = explode(':', $name);
$alias = $parts[0];
if (count($parts) > 1) {
$class = $parts[1];
} else {
$class = $parts[0];
}
if (!$class) {
$class = $alias;
}
$this->pools[$alias] = $pool = new Pool(new Definition($class), $num);
$pool->setFactory($this);
return $pool->getDefinition();
}
开发者ID:globalprofessionalsearch,项目名称:popov,代码行数:16,代码来源:Factory.php
示例17: get_dataksmurni
public function get_dataksmurni($date = false)
{
if (!$date) {
$date = date('Y-m-d');
}
$month = date('n', strtotime($date));
$year = date('Y', strtotime($date));
$series = array();
$categories = array();
foreach (Pool::all() as $pool) {
$datafianan = array();
for ($j = 1; $j <= date('t', strtotime($date)); $j++) {
$categories[] = $j;
$datafianan[] = 0;
}
$reportdaily = DB::table('financial_report_graf_ks_detail')->where_month($month)->where_year($year)->order_by('operasi_time', 'asc')->where_pool_id($pool->id)->where_in('operasi_status_id', array(1, 3))->where('setoran_cash', '<', 50000000)->group_by('operasi_time')->get(array('operasi_time', DB::raw('sum(ks) as subks')));
$arraydata = array();
foreach ($reportdaily as $finan) {
$potition = date('j', strtotime($finan->operasi_time)) - 1;
$arraydata[$potition] = (int) $finan->subks;
}
$datas = array_replace($datafianan, $arraydata);
$series[] = array('name' => $pool->pool_name, 'data' => $datas);
}
$returndata = array('categories' => $categories, 'series' => $series);
return json_encode($returndata);
}
开发者ID:acmadi,项目名称:diantaksi,代码行数:27,代码来源:reports.php
示例18: get_add
public function get_add()
{
$this->data['pools'] = Koki::to_dropdown(Pool::all(), 'id', 'pool_name', array(0 => 'All'));
$this->data['users'] = Koki::to_dropdown(User::all(), 'id', 'first_name');
$this->data['create'] = true;
return View::make('themes.modul.' . $this->views . '.form', $this->data);
}
开发者ID:acmadi,项目名称:diantaksi,代码行数:7,代码来源:news.php
示例19: wrap
public static function wrap($coroutine)
{
if ($coroutine instanceof \Generator) {
$coKey = $coroutine->key();
$coValue = $coroutine->current();
if ($coKey && in_array($coKey, self::$_ioQueue)) {
try {
$client = \Pool::get($coKey, $coValue);
if ($client) {
$client->setCoroutine($coroutine);
$coroutine->send($client);
} else {
Queue::push($coKey, $coroutine);
}
} catch (exception $e) {
$coroutine->throw($e);
}
} else {
if ($coValue instanceof \Coroutine\Base) {
$coValue->setCoroutine($coroutine);
}
}
}
return $coroutine;
}
开发者ID:jmuyuyang,项目名称:co-psf,代码行数:25,代码来源:Coroutine.php
示例20: get_datamonthly
public function get_datamonthly($date = false)
{
if (!$date) {
$date = date('Y-m-d');
}
$year = date('Y', strtotime($date));
$series = array();
$categories = array();
foreach (Pool::all() as $pool) {
$datafianan = array();
for ($j = 1; $j <= 12; $j++) {
$categories[] = $j;
$datafianan[] = 0;
}
$reportmonthly = DB::table('financial_report_summary_month_graf')->where_year($year)->order_by('operasi_time', 'asc')->where_pool_id($pool->id)->where('setoran_cash', '<', 993000000)->get();
$arraydata = array();
$bulan = 0;
foreach ($reportmonthly as $finan) {
$potition = $finan->month;
$arraydata[$potition] = (int) ($finan->setoran_cash - ($finan->biaya_cuci + $finan->iuran_laka));
}
$datas = array_replace($datafianan, $arraydata);
$series[] = array('name' => $pool->pool_name, 'data' => $datas);
}
$returndata = array('categories' => $categories, 'series' => $series);
return json_encode($returndata);
}
开发者ID:acmadi,项目名称:diantaksi,代码行数:27,代码来源:reportsnew.php
注:本文中的Pool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论