本文整理汇总了PHP中gc_disable函数的典型用法代码示例。如果您正苦于以下问题:PHP gc_disable函数的具体用法?PHP gc_disable怎么用?PHP gc_disable使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gc_disable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>');
$output->writeln('');
// config
$configFactory = new ConfigFactory();
$config = $configFactory->factory($input);
// files
if (null === $config->getPath()->getBasePath()) {
throw new \LogicException('Please provide a path to analyze');
}
// files to analyze
$finder = new Finder($config->getPath()->getExtensions(), $config->getPath()->getExcludedDirs(), $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null);
// prepare structures
$bounds = new Bounds();
$collection = new \Hal\Component\Result\ResultCollection();
$aggregatedResults = new \Hal\Component\Result\ResultCollection();
// execute analyze
$queueFactory = new QueueFactory($input, $output, $config);
$queue = $queueFactory->factory($finder, $bounds);
gc_disable();
$queue->execute($collection, $aggregatedResults);
gc_enable();
$output->writeln('<info>done</info>');
// evaluation of success
$evaluator = new Evaluator($collection, $aggregatedResults, $bounds);
$result = $evaluator->evaluate($config->getFailureCondition());
// fail if failure-condition is realized
return $result->isValid() ? 1 : 0;
}
示例2: yay_parse
function yay_parse(string $source, Directives $directives = null, BlueContext $blueContext = null) : string
{
if ($gc = gc_enabled()) {
gc_disable();
}
// important optimization!
static $globalDirectives = null;
if (null === $globalDirectives) {
$globalDirectives = new ArrayObject();
}
$directives = $directives ?: new Directives();
$blueContext = $blueContext ?: new BlueContext();
$cg = (object) ['ts' => TokenStream::fromSource($source), 'directives' => $directives, 'cycle' => new Cycle($source), 'globalDirectives' => $globalDirectives, 'blueContext' => $blueContext];
foreach ($cg->globalDirectives as $d) {
$cg->directives->add($d);
}
traverse(midrule(function (TokenStream $ts) use($directives, $blueContext) {
$token = $ts->current();
tail_call:
if (null === $token) {
return;
}
// skip when something looks like a new macro to be parsed
if ('macro' === (string) $token) {
return;
}
// here we do the 'magic' to match and expand userland macros
$directives->apply($ts, $token, $blueContext);
$token = $ts->next();
goto tail_call;
}), consume(chain(token(T_STRING, 'macro')->as('declaration'), optional(repeat(rtoken('/^·\\w+$/')))->as('tags'), lookahead(token('{')), commit(chain(braces()->as('pattern'), operator('>>'), braces()->as('expansion')))->as('body'), optional(token(';'))), CONSUME_DO_TRIM)->onCommit(function (Ast $macroAst) use($cg) {
$scope = Map::fromEmpty();
$tags = Map::fromValues(array_map('strval', $macroAst->{'tags'}));
$pattern = new Pattern($macroAst->{'declaration'}->line(), $macroAst->{'body pattern'}, $tags, $scope);
$expansion = new Expansion($macroAst->{'body expansion'}, $tags, $scope);
$macro = new Macro($tags, $pattern, $expansion, $cg->cycle);
$cg->directives->add($macro);
// allocate the userland macro
// allocate the userland macro globally if it's declared as global
if ($macro->tags()->contains('·global')) {
$cg->globalDirectives[] = $macro;
}
}))->parse($cg->ts);
$expansion = (string) $cg->ts;
if ($gc) {
gc_enable();
}
return $expansion;
}
示例3: processContent
/**
* @inheritdoc
* @throws ContentProcessorException
*/
public function processContent(File $asset)
{
$path = $asset->getPath();
try {
$parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
$content = $this->assetSource->getContent($asset);
if (trim($content) === '') {
return '';
}
$tmpFilePath = $this->temporaryFile->createFile($path, $content);
gc_disable();
$parser->parseFile($tmpFilePath, '');
$content = $parser->getCss();
gc_enable();
if (trim($content) === '') {
$errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
$this->logger->critical($errorMessage);
throw new ContentProcessorException(new Phrase($errorMessage));
}
return $content;
} catch (\Exception $e) {
$errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
$this->logger->critical($errorMessage);
throw new ContentProcessorException(new Phrase($errorMessage));
}
}
示例4: run
/**
* Runtime of Worker process.
* @return void
*/
protected function run()
{
if (Daemon::$process instanceof Master) {
Daemon::$process->unregisterSignals();
}
EventLoop::init();
Daemon::$process = $this;
if (Daemon::$logpointerAsync) {
Daemon::$logpointerAsync->fd = null;
Daemon::$logpointerAsync = null;
}
class_exists('Timer');
if (Daemon::$config->autogc->value > 0) {
gc_enable();
} else {
gc_disable();
}
$this->prepareSystemEnv();
$this->registerEventSignals();
FileSystem::init();
// re-init
FileSystem::initEvent();
Daemon::openLogs();
$this->fileWatcher = new FileWatcher();
$this->IPCManager = Daemon::$appResolver->getInstanceByAppName('\\PHPDaemon\\IPCManager\\IPCManager');
if (!$this->IPCManager) {
$this->log('cannot instantiate IPCManager');
}
EventLoop::$instance->run();
}
示例5: huffman_lookup_init
private static function huffman_lookup_init()
{
gc_disable();
$encodingAccess = [];
$terminals = [];
foreach (self::HUFFMAN_CODE as $chr => $bits) {
$len = self::HUFFMAN_CODE_LENGTHS[$chr];
for ($bit = 0; $bit < 8; $bit++) {
$offlen = $len + $bit;
$next =& $encodingAccess[$bit];
for ($byte = (int) (($offlen - 1) / 8); $byte > 0; $byte--) {
$cur = \str_pad(\decbin($bits >> $byte * 8 - (0x30 - $offlen) % 8 & 0xff), 8, "0", STR_PAD_LEFT);
if (isset($next[$cur]) && $next[$cur][0] != $encodingAccess[0]) {
$next =& $next[$cur][0];
} else {
$tmp =& $next;
unset($next);
$tmp[$cur] = [&$next, null];
}
}
$key = \str_pad(\decbin($bits & (1 << ($offlen - 1) % 8 + 1) - 1), ($offlen - 1) % 8 + 1, "0", STR_PAD_LEFT);
$next[$key] = [null, $chr > 0xff ? "" : \chr($chr)];
if ($offlen % 8) {
$terminals[$offlen % 8][] = [$key, &$next];
} else {
$next[$key][0] =& $encodingAccess[0];
}
}
}
$memoize = [];
for ($off = 7; $off > 0; $off--) {
foreach ($terminals[$off] as &$terminal) {
$key = $terminal[0];
$next =& $terminal[1];
if ($next[$key][0] === null) {
foreach ($encodingAccess[$off] as $chr => &$cur) {
$next[($memoize[$key] ?? ($memoize[$key] = \str_pad($key, 8, "0", STR_PAD_RIGHT))) | $chr] = [&$cur[0], $next[$key][1] != "" ? $next[$key][1] . $cur[1] : ""];
}
unset($next[$key]);
}
}
}
$memoize = [];
for ($off = 7; $off > 0; $off--) {
foreach ($terminals[$off] as &$terminal) {
$next =& $terminal[1];
foreach ($next as $k => $v) {
if (\strlen($k) != 1) {
$next[$memoize[$k] ?? ($memoize[$k] = \chr(\bindec($k)))] = $v;
unset($next[$k]);
}
}
}
}
unset($tmp, $cur, $next, $terminals, $terminal);
gc_enable();
gc_collect_cycles();
return $encodingAccess[0];
}
示例6: __construct
public function __construct($bridgeName = null, $appBootstrap, array $config = [])
{
gc_disable();
$this->config = $config;
$this->appBootstrap = $appBootstrap;
$this->bridgeName = $bridgeName;
$this->run();
}
示例7: execute
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>');
$output->writeln('');
// config
$configFactory = new ConfigFactory();
$config = $configFactory->factory($input);
// files
if (null === $config->getPath()->getBasePath()) {
throw new \LogicException('Please provide a path to analyze');
}
// files to analyze
$finder = new Finder($config->getPath()->getExtensions(), $config->getPath()->getExcludedDirs(), $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null);
// prepare plugins
$repository = new Repository();
foreach ($config->getExtensions()->getExtensions() as $filename) {
if (!file_exists($filename) || !is_readable($filename)) {
$output->writeln(sprintf('<error>Plugin %s skipped: not found</error>', $filename));
continue;
}
$plugin = (require_once $filename);
$repository->attach($plugin);
}
$extensionService = new ExtensionService($repository);
// prepare structures
$bounds = new Bounds();
$collection = new ResultCollection();
$aggregatedResults = new ResultCollection();
// execute analyze
$queueFactory = new QueueAnalyzeFactory($input, $output, $config, $extensionService);
$queue = $queueFactory->factory($finder, $bounds);
gc_disable();
$queue->execute($collection, $aggregatedResults);
gc_enable();
$output->writeln('');
// provide data to extensions
if (($n = sizeof($repository->all())) > 0) {
$output->writeln(sprintf('%d %s. Executing analyzis', $n, $n > 1 ? 'plugins are enabled' : 'plugin is enabled'));
$extensionService->receive($config, $collection, $aggregatedResults, $bounds);
}
// generating reports
$output->writeln("Generating reports...");
$queueFactory = new QueueReportFactory($input, $output, $config, $extensionService);
$queue = $queueFactory->factory($finder, $bounds);
$queue->execute($collection, $aggregatedResults);
$output->writeln('<info>Done</info>');
// evaluation of success
$rule = $config->getFailureCondition();
if (null !== $rule) {
$evaluator = new Evaluator($collection, $aggregatedResults, $bounds);
$result = $evaluator->evaluate($rule);
// fail if failure-condition is realized
return $result->isValid() ? 1 : 0;
}
return 0;
}
示例8: setUp
protected function setUp()
{
parent::setUp();
// disable GC while https://bugs.php.net/bug.php?id=63677 is still open
// If GC enabled, Gmagick unit tests fail
gc_disable();
if (!class_exists('Gmagick')) {
$this->markTestSkipped('Gmagick is not installed');
}
}
示例9: gc
/**
* Gc
*/
private function gc()
{
if (gc_enabled()) {
gc_collect_cycles();
} else {
gc_enable();
gc_collect_cycles();
gc_disable();
}
}
示例10: clean
public static function clean($print = false)
{
gc_enable();
// Enable Garbage Collector
if ($print) {
AppLog::log(gc_collect_cycles() . " garbage cycles cleaned");
// # of elements cleaned up
}
gc_disable();
// Disable Garbage Collector
}
示例11: formatCode
public function formatCode($source = '')
{
gc_enable();
$passes = array_map(function ($pass) {
return clone $pass;
}, $this->passes);
while ($pass = array_shift($passes)) {
$source = $pass->format($source);
gc_collect_cycles();
}
gc_disable();
return $source;
}
示例12: doBench
private static function doBench(callable $func, array $args)
{
gc_collect_cycles();
gc_disable();
usleep(0);
$t = microtime(true);
for ($i = self::$iterations; $i >= 0; --$i) {
call_user_func_array($func, $args);
}
$t = microtime(true) - $t;
gc_enable();
gc_collect_cycles();
usleep(0);
return round($t * 1000000 / self::$iterations, 3);
}
示例13: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
gc_disable();
$this->output = $output;
$this->router->getContext()->setScheme($this->config['scheme']);
$this->router->getContext()->setHost($this->config['host']);
$start = time();
$name = $input->getOption('name');
if ($name && !$this->runSingleSitemap($name)) {
return 1;
} else {
$this->runMultiSitemaps();
}
$this->output->writeln($this->getHelper('formatter')->formatBlock(['[Info]', sprintf('Mission Accomplished in %d s', time() - $start)], ConsoleLogger::INFO));
return 0;
}
示例14: timeExec
protected static function timeExec(callable $code, $rounds)
{
$gc_enabled = gc_enabled();
if ($gc_enabled) {
gc_disable();
}
$start = microtime(TRUE);
for ($i = 0; $i < $rounds; $i++) {
$code();
}
$end = microtime(TRUE);
if ($gc_enabled) {
gc_enable();
}
return $end - $start;
}
示例15: install
function install($diff)
{
if (!file_exists($diff)) {
return;
}
gc_enable();
$root = __DIR__ . "/../../";
$archive = new ZipArchive();
$archive->open($diff);
$bower = $archive->locateName("bower.json");
$webDir = $root . "web";
if (!file_exists($webDir)) {
mkdir($webDir);
}
$privateDir = $root . "private";
if (!file_exists($privateDir)) {
mkdir($privateDir);
}
if ($bower) {
$bowerDir = $root . "web/vendor";
if (file_exists($bowerDir)) {
$this->rrmdir($bowerDir);
}
mkdir($bowerDir);
}
$composer = $archive->locateName("composer.json");
if ($composer) {
$composerDir = $root . "private/vendor";
if (file_exists($composerDir)) {
$this->rrmdir($composerDir);
}
mkdir($composerDir);
}
$tempDir = $root . "private/temp";
$this->rrmdir($tempDir);
mkdir($tempDir);
$archive->extractTo($root);
@unlink($diff);
unset($archive);
gc_collect_cycles();
gc_disable();
}