本文整理汇总了PHP中gc_enabled函数的典型用法代码示例。如果您正苦于以下问题:PHP gc_enabled函数的具体用法?PHP gc_enabled怎么用?PHP gc_enabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gc_enabled函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: tearDown
protected function tearDown()
{
//Close & unsets
if (is_object($this->em)) {
$this->em->getConnection()->close();
$this->em->close();
}
unset($this->em);
unset($this->container);
unset($this->kern);
unset($this->client);
//Nettoyage des mocks
//http://kriswallsmith.net/post/18029585104/faster-phpunit
$refl = new \ReflectionObject($this);
foreach ($refl->getProperties() as $prop) {
if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
$prop->setAccessible(true);
$prop->setValue($this, null);
}
}
//Nettoyage du garbage
if (!gc_enabled()) {
gc_enable();
}
gc_collect_cycles();
//Parent
parent::tearDown();
}
示例3: __destruct
/**
* Remove items that link back to this before destroying this object
*/
public function __destruct()
{
if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
{
unset($this->feed);
}
}
示例4: iterate
protected function iterate($seconds)
{
sleep($seconds);
if (!gc_enabled()) {
gc_enable();
}
gc_collect_cycles();
}
示例5: __construct
public function __construct()
{
$this->checkPcntl();
// Enable PHP 5.3 garbage collection
if (function_exists('gc_enable')) {
gc_enable();
$this->gc = gc_enabled();
}
}
示例6: setUpBeforeClass
/**
* {@inheritdoc}
*/
public static function setUpBeforeClass()
{
// enables garbage collector because symfony/phpunit-bridge disables it. see:
// see: https://github.com/symfony/symfony/pull/13398/files#diff-81bfee6017752d99d3119f4ddb1a09edR1
// see: https://github.com/symfony/symfony/pull/13398 (feature list)
if (!gc_enabled()) {
gc_enable();
}
}
示例7: Initialize
/**
* In the constructor we'll simply initialise the earlier two properties,
* respectivily with an array and the current timestamp.
*/
public static function Initialize()
{
self::$s_pStatistics = new \stdClass();
self::$s_pStatistics->Memory = 0;
self::$s_pStatistics->Cycles = 0;
self::$s_nLastCollect = time();
if (!gc_enabled()) {
gc_enable();
}
}
示例8: gc
/**
* Gc
*/
private function gc()
{
if (gc_enabled()) {
gc_collect_cycles();
} else {
gc_enable();
gc_collect_cycles();
gc_disable();
}
}
示例9: onStopConditionCheck
/**
* @param WorkerEvent $event
* @return void
*/
public function onStopConditionCheck(WorkerEvent $event)
{
// @see http://php.net/manual/en/features.gc.collecting-cycles.php
if (gc_enabled()) {
gc_collect_cycles();
}
$usage = memory_get_usage();
if ($this->maxMemory && $usage > $this->maxMemory) {
$event->exitWorkerLoop();
$this->state = sprintf("memory threshold of %s exceeded (usage: %s)", $this->humanFormat($this->maxMemory), $this->humanFormat($usage));
} else {
$this->state = sprintf('%s memory usage', $this->humanFormat($usage));
}
}
示例10: 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;
}
示例11: check_pcntl
/**
* 环境检查
* @throws Exception
*/
public function check_pcntl()
{
// Make sure PHP has support for pcntl
if (!function_exists('pcntl_signal')) {
$message = 'PHP does not appear to be compiled with the PCNTL extension. This is neccesary for daemonization';
throw new Exception($message);
}
//信号处理
pcntl_signal(SIGTERM, array(&$this, "signal_handler"));
pcntl_signal(SIGINT, array(&$this, "signal_handler"));
pcntl_signal(SIGQUIT, array(&$this, "signal_handler"));
// Enable PHP 5.3 garbage collection
if (function_exists('gc_enable')) {
gc_enable();
$this->gc_enabled = gc_enabled();
}
}
示例12: __construct
public function __construct($socket_url, $protocol_name, $transport_name = 'Socket')
{
if (PHP_SAPI !== 'cli') {
throw new LogicException("Daemonic Application should be run using CLI SAPI");
}
if (version_compare("5.3.0", PHP_VERSION, '>')) {
throw new LogicException("Daemonic Application requires PHP 5.3.0+");
}
// Checking for GarbageCollection patch
if (false === gc_enabled()) {
gc_enable();
}
$transport_class = 'MFS\\AppServer\\Transport\\' . $transport_name;
$this->setTransport(new $transport_class($socket_url, array($this, 'onRequest')));
$protocol_class = 'MFS\\AppServer\\' . $protocol_name . '\\Server';
$this->setProtocol(new $protocol_class());
$this->log('Initialized Daemonic Handler');
}
示例13: check_pcntl
public function check_pcntl()
{
if (!function_exists('pcntl_signal_dispatch')) {
// PHP < 5.3 uses ticks to handle signals instead of pcntl_signal_dispatch
// call sighandler only every 10 ticks
declare (ticks=1);
}
// Make sure PHP has support for pcntl
if (!function_exists('pcntl_signal')) {
$message = 'PHP does not appear to be compiled with the PCNTL extension. This is neccesary for daemonization';
throw new \Exception($message);
}
//信号处理
\pcntl_signal(SIGTERM, array(__CLASS__, "signal_handler"), false);
\pcntl_signal(SIGINT, array(__CLASS__, "signal_handler"), false);
\pcntl_signal(SIGQUIT, array(__CLASS__, "signal_handler"), false);
// Enable PHP 5.3 garbage collection
if (\function_exists('gc_enable')) {
\gc_enable();
$this->gc_enabled = \gc_enabled();
}
}
示例14: gc_disable
<?php
gc_disable();
var_dump(gc_enabled());
gc_enable();
var_dump(gc_enabled());
示例15: __
echo __('PHP Actual Configuration Memory Limit', 'bulletproof-security') . ': <strong><font color="blue">' . __('The Memory Limit value is not available from your Server.', 'bulletproof-security') . '</font></strong><br>';
} else {
switch ($memoryLimit) {
case $memoryLimit >= '128':
echo __('PHP Actual Configuration Memory Limit', 'bulletproof-security') . ': <strong><font color="green">' . $memoryLimitM . '</font></strong><br>';
break;
case $memoryLimit >= '65' && $memoryLimit < '128':
echo __('PHP Actual Configuration Memory Limit', 'bulletproof-security') . ': <strong><font color="blue">' . $memoryLimitM . __(' Recommendation: Increase Memory Limit to 128M.', 'bulletproof-security') . '</font></strong><br>';
break;
case $memoryLimit > '0' && $memoryLimit <= '64':
echo __('PHP Actual Configuration Memory Limit', 'bulletproof-security') . ': <strong><font color="red">' . $memoryLimitM . __(' Recommendation: Increase Memory Limit to 128M.', 'bulletproof-security') . '</font></strong><br>';
break;
}
}
if (function_exists('gc_enabled') && function_exists('gc_collect_cycles')) {
if (gc_enabled()) {
$garbage = 'On | Cycles: ' . gc_collect_cycles();
} else {
$garbage = 'Off';
}
echo __('Garbage Collector', 'bulletproof-security') . ': <strong>' . $garbage . '</strong><br>';
}
echo __('PHP Max Upload Size', 'bulletproof-security') . ': ';
$upload_max = ini_get('upload_max_filesize');
echo '<strong>' . $upload_max . '</strong><br>';
echo __('PHP Max Post Size', 'bulletproof-security') . ': ';
$post_max = ini_get('post_max_size');
echo '<strong>' . $post_max . '</strong><br>';
echo __('PHP Safe Mode', 'bulletproof-security') . ': ';
if (ini_get('safe_mode') == 1) {
$text = '<font color="red"><strong>' . __('On', 'bulletproof-security') . '</strong></font>';