本文整理汇总了PHP中Pool::submit方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::submit方法的具体用法?PHP Pool::submit怎么用?PHP Pool::submit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pool
的用法示例。
在下文中一共展示了Pool::submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: submitTask
public function submitTask(AsyncTask $task)
{
if ($task->isGarbage()) {
return;
}
$this->tasks[$task->getTaskId()] = $task;
$this->pool->submit($task);
}
示例3: scheduleAsyncTask
/**
* Submits a asynchronous task to the Pool
* If the AsyncTask sets a result, you have to get it so it can be deleted
*
* @param AsyncTask $task
*
* @return void
*/
public function scheduleAsyncTask(AsyncTask $task)
{
$id = $this->nextId();
$task->setTaskId($id);
$this->asyncPool->submit($task);
$this->asyncTaskStorage[$id] = $task;
++$this->asyncTasks;
}
示例4: useMultiCore1
public function useMultiCore1()
{
$core = $this->getCoreCount();
$pool = new \Pool($core);
for ($i = 0; $i < $core; $i++) {
$pool->submit(new ProveWorker());
}
}
示例5: submit
public function submit(Threaded $threaded)
{
if (!$threaded instanceof PipeAware or !$threaded instanceof VolatileAware) {
throw new \InvalidArgumentException("Threadeds submitted to OnDemandePool should implement both PipeAware and VolatileAware");
}
$threaded->setPipe($this->getPipe());
$threaded->setVolatile($this->getPacket());
parent::submit($threaded);
}
示例6: 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);
});
}
示例7: __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();
}
示例8: submit
public function submit(\Threaded $thread, $loop)
{
parent::submit($thread);
return Observable::create(function (ObserverInterface $observer) use($thread, $loop) {
while ($thread->isRunning()) {
$loop->tick();
//var_dump($thread->isRunning());
//usleep(100);
}
$observer->onNext(new Event('/thread/ok', $thread));
$observer->onCompleted();
});
}
示例9: 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];
}
示例10: Init
public static function Init()
{
$config = \Rds\Configuration::get();
$boot = \Rds\Bootstrap::getInstace($config);
$totalPages = $boot->getTotalPages();
if ($totalPages > 0) {
$pool = new \Pool($config["app"]["workers"], \Rds\Worker::class, array("Vendor/autoload.php", new \Rds\StackableConfig($config)));
for ($page = 1; $page <= $totalPages; $page++) {
$task = new \Rds\Task($page);
$pool->submit($task);
}
$pool->shutdown();
$pool->collect(function ($work) {
return $work->isGarbage();
});
}
}
示例11: run
class Example extends Thread
{
public function run()
{
dump('foobar');
}
}
// Faulty example
//////////////////////////////////////////////////////////////////////
$job = new Example();
$job->start();
$job->join();
// Now let's fix our example
//////////////////////////////////////////////////////////////////////
class AutoloadingWorker extends Worker
{
public function run()
{
require 'vendor/autoload.php';
}
}
// Create our worker and stack our job on it
$worker = new AutoloadingWorker();
$job = new Example();
$worker->stack($job);
$worker->start();
$worker->join();
// Or use a pool and specify our custom worker
$pool = new Pool(5, AutoloadingWorker::class);
$pool->submit(new Example());
$pool->shutdown();
示例12: Pool
<?php
/* include autoloader normally */
require_once "vendor/autoload.php";
use Auto\Autoloader;
use Auto\Task;
/* create pool of workers of the specified class, passing the specified
path to autoloader */
$pool = new Pool(4, Autoloader::class, ["vendor/autoload.php"]);
/* submit a task to the pool */
$pool->submit(new Task("Hello World!"));
/* in the real world, do some ::collect somewhere */
/* shutdown, because explicit is good */
$pool->shutdown();
示例13: __get
/* getting a value on the channel shall cause callers to wait until it's available */
public final function __get($key)
{
return $this->synchronized(function () use($key) {
while (!isset($this[$key])) {
$this->wait();
}
return $this[$key];
});
}
}
class Routine extends Threaded
{
public function __construct(Channel $channel)
{
$this->channel = $channel;
}
public function run()
{
/* sending on the channel */
$this->channel["message"] = "Hello World";
$this->channel["gold"] = 3.462;
}
protected $channel;
}
$channel = new Channel();
$pool = new Pool(4);
$pool->submit(new Routine($channel));
/* recving on the channel */
printf("Message: %s, Gold: %.3f\n", $channel["message"], $channel["gold"]);
$pool->shutdown();
示例14: run
public function run()
{
$mysqli = $this->worker->getConnection();
$result = $mysqli->query($this->sql);
if ($result) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
}
$this->result = $rows;
}
public function getResult()
{
return $this->result;
}
protected $sql;
protected $result;
}
$pool = new Pool(4, "Connect", ["localhost", "root", "", "mysql"]);
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->submit(new Query("SHOW PROCESSLIST;"));
$pool->shutdown();
/* ::collect is used here for shorthand to dump query results */
$pool->collect(function ($query) {
var_dump($done = $query->getResult());
return count($done);
});
示例15: shutdown
}
/* Shutdown the pool of threads cleanly, retaining exit status locally */
public function shutdown()
{
foreach ($this->workers as $worker) {
$this->status[$worker->getThreadId()] = $worker->shutdown();
}
}
}
$start = microtime(true);
/* Create a pool of ten threads */
$pool = new Pool(10);
/* Create and submit an array of Stackables */
$work = array();
while (++$target < 100) {
$work[] = $pool->submit(new ExampleWork(array_rand($_SERVER)));
}
$pool->shutdown();
/*
* Look inside
*/
$runtime = microtime(true) - $start;
if ($_SERVER["HTTP_HOST"]) {
echo "<pre>";
}
printf("---------------------------------------------------------\n");
printf("Executed %d tasks in %f seconds in %d threads\n", count($work), $runtime, 10);
printf("---------------------------------------------------------\n");
if ($_SERVER["HTTP_HOST"]) {
printf("%s | %.3fMB RAM\n", $_SERVER["SERVER_SOFTWARE"], memory_get_peak_usage(true) / 1048576);
} else {