本文整理汇总了PHP中Pool::shutdown方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::shutdown方法的具体用法?PHP Pool::shutdown怎么用?PHP Pool::shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pool
的用法示例。
在下文中一共展示了Pool::shutdown方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cancelAllTasks
public function cancelAllTasks()
{
foreach ($this->tasks as $task) {
$task->cancel();
}
$this->tasks = [];
$this->asyncPool->shutdown();
$this->asyncTasks = 0;
}
示例2: 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);
});
}
示例3: __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();
}
示例4: 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];
}
示例5: 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();
});
}
}
示例6: 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();
示例7: 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();
}
示例8: serialize
file_put_contents(IAPROGRESS . WIKIPEDIA . UNIQUEID . "stats", serialize(array('linksAnalyzed' => $linksAnalyzed, 'linksArchived' => $linksArchived, 'linksFixed' => $linksFixed, 'linksTagged' => $linksTagged, 'pagesModified' => $pagesModified, 'pagesAnalyzed' => $pagesAnalyzed, 'runstart' => $runstart)));
}
if (file_exists(IAPROGRESS . WIKIPEDIA . UNIQUEID . "workers/")) {
closedir($handle);
}
$workerQueue = new Pool($workerLimit);
foreach ($pages as $tid => $tpage) {
$pagesAnalyzed++;
$runpagecount++;
echo "Submitted {$tpage['title']}, job " . ($tid + 1) . " for analyzing...\n";
$workerQueue->submit(new ThreadedBot($tpage['title'], $tpage['pageid'], $ARCHIVE_ALIVE, $TAG_OVERRIDE, $ARCHIVE_BY_ACCESSDATE, $TOUCH_ARCHIVE, $DEAD_ONLY, $NOTIFY_ERROR_ON_TALK, $NOTIFY_ON_TALK, $TALK_MESSAGE_HEADER, $TALK_MESSAGE, $TALK_ERROR_MESSAGE_HEADER, $TALK_ERROR_MESSAGE, $DEADLINK_TAGS, $CITATION_TAGS, $IGNORE_TAGS, $WAYBACK_TAGS, $WEBCITE_TAGS, $MEMENTO_TAGS, $ARCHIVEIS_TAGS, $ARCHIVE_TAGS, $IC_TAGS, $PAYWALL_TAGS, $VERIFY_DEAD, $LINK_SCAN, $NOTIFY_ON_TALK_ONLY, $MLADDARCHIVE, $MLMODIFYARCHIVE, $MLTAGGED, $MLTAGREMOVED, $MLFIX, $MLDEFAULT, $PLERROR, $MAINEDITSUMMARY, $ERRORTALKEDITSUMMARY, $TALKEDITSUMMARY, $tid));
if (LIMITEDRUN === true && is_int($debugStyle) && $debugStyle === $runpagecount) {
break;
}
}
$workerQueue->shutdown();
$workerQueue->collect(function ($thread) {
global $pagesModified, $linksAnalyzed, $linksArchived, $linksFixed, $linksTagged;
$stats = $thread->result;
if ($stats['pagemodified'] === true) {
$pagesModified++;
}
$linksAnalyzed += $stats['linksanalyzed'];
$linksArchived += $stats['linksarchived'];
$linksFixed += $stats['linksrescued'];
$linksTagged += $stats['linkstagged'];
$stats = null;
unset($stats);
return $thread->isGarbage();
});
if (file_exists(IAPROGRESS . WIKIPEDIA . UNIQUEID . "workers/") && ($handle = opendir(IAPROGRESS . WIKIPEDIA . UNIQUEID . "workers"))) {
示例9: run
/**
*
*/
public function run()
{
// Reap the threads!
$this->websocket->loop->addPeriodicTimer(600, function () {
$this->log->addInfo('Restarting the threading pool, to clear out old threads..');
// Shutdown the pool
$this->pool->shutdown();
$this->timers->shutdown();
// Startup the pool again
$this->pool = new \Pool(count($this->onMessage), \Worker::class);
$this->timers = new \Pool(count($this->onTimer), \Worker::class);
});
// Handle the onReady event, and setup some timers and so forth
$this->websocket->on('ready', function (Discord $discord) {
$this->log->addInfo('Websocket connected..');
// Update our presence status
$game = new Game(array('name' => $this->globalConfig->get('presence', 'bot', "table flippin'"), 'url' => null, 'type' => null), true);
$this->websocket->updatePresence($game, false);
// Count the amount of people we are available to..
/** @var Guild $guild */
foreach ($this->discord->getClient()->getGuildsAttribute()->all() as $guild) {
$this->extras['memberCount'] += $guild->member_count;
$this->extras['guildCount']++;
$this->extras['guild']['memberCount']["id{$guild->id}"] = $guild->member_count;
$this->extras['onMessagePlugins'] = $this->onMessage;
$this->extras['onVoicePlugins'] = $this->onVoice;
}
$this->log->addInfo("Member count, currently available to: {$this->extras['memberCount']} people");
// Setup the timers for the timer plugins
foreach ($this->onTimer as $command => $data) {
$this->websocket->loop->addPeriodicTimer($data['timer'], function () use($data, $discord) {
try {
$plugin = new $data['class']($discord, $this->log, $this->globalConfig, $this->db, $this->curl, $this->settings, $this->permissions, $this->container->get('serverConfig'), $this->users, $this->extras);
$this->timers->submit($plugin);
} catch (\Exception $e) {
$this->log->addError("Error running the periodic timer: {$e->getMessage()}");
}
});
}
// Issue periodically recounting and other things (Needed because of pthreads not putting the entire context into children - leading to some weirdness in some plugins)
$this->websocket->loop->addPeriodicTimer(600, function () {
$this->extras['memberCount'] = 0;
$this->extras['guildCount'] = 0;
/** @var Guild $guild */
foreach ($this->discord->getClient()->getGuildsAttribute()->all() as $guild) {
$this->extras['memberCount'] += $guild->member_count;
$this->extras['guildCount']++;
$this->extras['guild']['memberCount']["id{$guild->id}"] = $guild->member_count;
$this->extras['onMessagePlugins'] = $this->onMessage;
$this->extras['onVoicePlugins'] = $this->onVoice;
}
// Output periodic information while doing the recounting stuff
$this->log->addInfo('Currently running audio streams: ' . count($this->audioStreams));
$this->log->addInfo("Member recount, currently available to: {$this->extras['memberCount']} people");
});
// @todo run a timer to check if there are any active voice sessions - and if there are, if there are any people in those voice sessions
// If not, stop the session and leave the channel (To save some bandwidth)
});
$this->websocket->on('error', function ($error, $websocket) {
$this->log->addError('An error occurred on the websocket', [$error->getMessage()]);
die(1);
});
$this->websocket->on('close', function ($opCode, $reason) {
$this->log->addWarning('Websocket got closed', ['code' => $opCode, 'reason' => $reason]);
die(1);
});
$this->websocket->on('reconnecting', function () {
$this->log->addInfo('Websocket is reconnecting..');
});
$this->websocket->on('reconnected', function () {
$this->log->addInfo('Websocket was reconnected..');
});
// Handle incoming message logging
$this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
$this->log->addInfo("Message from {$message->author->username}", [$message->content]);
// Don't update data for ourselves..
if ($message->author->id !== $discord->getClient()->id) {
$this->users->set($message->author->id, $message->author->username, 'online', null, date('Y-m-d H:i:s'), date('Y-m-d H:i:s'), $message->content);
}
// @todo Create text logs
});
// Handle plugin running
$this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
$guildID = $message->getChannelAttribute()->guild_id;
// Get server config
$config = $this->settings->get($guildID);
// Is the person admin?
$userDiscordID = $message->author->id;
foreach ($this->globalConfig->get('admins', 'permissions') as $admins) {
$message->isAdmin = $admins === $userDiscordID;
}
// Define the prefix if it isn't already set..
@($config->prefix = $config->prefix ?? $this->globalConfig->get('prefix', 'bot'));
// Check if the user requested an onMessage plugin
if (substr($message->content, 0, strlen($config->prefix)) === $config->prefix) {
$content = explode(' ', $message->content);
foreach ($this->onMessage as $command => $data) {
//.........这里部分代码省略.........
示例10: removeTasks
public function removeTasks()
{
$this->pool->shutdown();
}