當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Pool類代碼示例

本文整理匯總了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}";
 }
開發者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


注:本文中的Pool類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。