本文整理汇总了PHP中gc_enabled函数的典型用法代码示例。如果您正苦于以下问题:PHP gc_enabled函数的具体用法?PHP gc_enabled怎么用?PHP gc_enabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gc_enabled函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:lastguest,项目名称:yay,代码行数:49,代码来源:yay_parse.php
示例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();
}
开发者ID:Reallymute,项目名称:IRMApplicative,代码行数:28,代码来源:CarmaWebTestCase.php
示例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);
}
}
开发者ID:nicola-amatucci,项目名称:fuel-simplepie,代码行数:10,代码来源:item.php
示例4: iterate
protected function iterate($seconds)
{
sleep($seconds);
if (!gc_enabled()) {
gc_enable();
}
gc_collect_cycles();
}
开发者ID:Hypnobox,项目名称:daemon,代码行数:8,代码来源:Daemon.php
示例5: __construct
public function __construct()
{
$this->checkPcntl();
// Enable PHP 5.3 garbage collection
if (function_exists('gc_enable')) {
gc_enable();
$this->gc = gc_enabled();
}
}
开发者ID:shaogx,项目名称:easyJob,代码行数:9,代码来源:Command.php
示例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();
}
}
开发者ID:sulu,项目名称:sulu,代码行数:12,代码来源:SuluTestCase.php
示例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();
}
}
开发者ID:xhoogland,项目名称:Monique,代码行数:14,代码来源:Memory.php
示例8: gc
/**
* Gc
*/
private function gc()
{
if (gc_enabled()) {
gc_collect_cycles();
} else {
gc_enable();
gc_collect_cycles();
gc_disable();
}
}
开发者ID:gridguyz,项目名称:zork,代码行数:13,代码来源:AbstractHttpControllerTestCase.php
示例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));
}
}
开发者ID:jackdpeterson,项目名称:SlmQueue,代码行数:18,代码来源:MaxMemoryStrategy.php
示例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;
}
开发者ID:flaviovs,项目名称:timeit,代码行数:16,代码来源:Timer.php
示例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();
}
}
开发者ID:songguang-2010,项目名称:Zebra-Daemon,代码行数:21,代码来源:DaemonSingle.php
示例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');
}
开发者ID:bermi,项目名称:akelos,代码行数:18,代码来源:DaemonicHandler.class.php
示例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();
}
}
开发者ID:songguang-2010,项目名称:Zebra-Daemon,代码行数:22,代码来源:Daemon.php
示例14: gc_disable
<?php
gc_disable();
var_dump(gc_enabled());
gc_enable();
var_dump(gc_enabled());
开发者ID:badlamer,项目名称:hhvm,代码行数:6,代码来源:gc_001.php
示例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>';
开发者ID:konsultanblog,项目名称:tagamon,代码行数:31,代码来源:system-info_1.php
示例16: __construct
public function __construct()
{
if (!gc_enabled()) {
gc_enable();
}
}
开发者ID:nfx,项目名称:AsyncBundle,代码行数:6,代码来源:Daemon.php
示例17:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
// Detect if we're loaded by an actual run of phpunit
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false)) {
return;
}
if (PHP_VERSION_ID >= 50400 && gc_enabled()) {
// Disabling Zend Garbage Collection to prevent segfaults with PHP5.4+
// https://bugs.php.net/bug.php?id=53976
gc_disable();
}
if (class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry')) {
AnnotationRegistry::registerLoader('class_exists');
}
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
开发者ID:lamzin-andrey,项目名称:skyengtt.loc,代码行数:17,代码来源:bootstrap.php
示例18: set_time_limit
<?php
include 'ProcessControl.php';
set_time_limit(0);
if (false == gc_enabled()) {
gc_enable();
}
$options = getopt('dhP:u:');
if (isset($options['h'])) {
echo <<<'HELP'
-d run as a daemon
-h print this help and exit
-u <username> assume identity of <username> (only when run as root)
HELP;
exit(0);
}
try {
$manager = new Fork\Manager(function () {
$children = new Fork\Children();
$gearman = new Fork\Worker\PeclGearman(function () {
return include 'GearmanWorker.php';
});
// Run 5 gearmans each restarting after an hour
$children->createProcesses(new Fork\Worker\ExitAfterDuration($gearman, 3600), 5);
return $children;
});
// Daemonize?
if (isset($options['d'])) {
$daemon = new ProcessControl\Daemon();
if (isset($options['u'])) {
开发者ID:JaredWilliams,项目名称:PHPGearmanToolkit,代码行数:31,代码来源:Worker.php
示例19: error_reporting
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (!gc_enabled()) {
gc_enable();
}
if (!extension_loaded("pthreads")) {
die("Please install pthreads extension !");
}
if (file_exists('vendor/autoload.php')) {
require 'vendor/autoload.php';
} else {
die("Please install composer and run 'composer install' !" . PHP_EOL);
}
use Emulator\Emulator;
Emulator::start();
开发者ID:BurakDev,项目名称:BloonPHP,代码行数:17,代码来源:main.php
示例20: watch
//.........这里部分代码省略.........
if ($c) {
foreach ($cp as $fileName => $mt) {
unset($o->patterns->{$fileName});
$patternParts = explode(DIRECTORY_SEPARATOR, $fileName);
$pattern = isset($patternParts[2]) ? $patternParts[2] : $patternParts[1];
unset($this->patternPaths[$patternParts[0]][$pattern]);
$this->updateSite($fileName, "removed");
}
}
// iterate over the data files and regenerate the entire site if they've changed
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd . "/_data/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach ($objects as $name => $object) {
$fileName = str_replace($this->sd . "/_data" . DIRECTORY_SEPARATOR, "", $name);
$mt = $object->getMTime();
if (!isset($o->{$fileName})) {
$o->{$fileName} = $mt;
if ($fileName[0] != "_" && $object->isFile()) {
$this->moveStaticFile("_data/" . $fileName, "", "_data", "data");
}
} else {
if ($o->{$fileName} != $mt) {
$o->{$fileName} = $mt;
$this->updateSite($fileName, "changed");
if ($fileName[0] != "_" && $object->isFile()) {
$this->moveStaticFile("_data/" . $fileName, "", "_data", "data");
}
}
}
}
// iterate over all of the other files in the source directory and move them if their modified time has changed
if ($moveStatic) {
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sd . "/"), \RecursiveIteratorIterator::SELF_FIRST);
// make sure dots are skipped
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
foreach ($objects as $name => $object) {
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
$fileName = str_replace($this->sd . DIRECTORY_SEPARATOR, "", $name);
if ($fileName[0] != "_" && !in_array($object->getExtension(), $this->ie) && !in_array($object->getFilename(), $this->id)) {
// catch directories that have the ignored dir in their path
$ignoreDir = $this->ignoreDir($fileName);
// check to see if it's a new directory
if (!$ignoreDir && $object->isDir() && !isset($o->{$fileName}) && !is_dir($this->pd . "/" . $fileName)) {
mkdir($this->pd . "/" . $fileName);
$o->{$fileName} = "dir created";
// placeholder
print $fileName . "/ directory was created...\n";
}
// check to see if it's a new file or a file that has changed
if (file_exists($name)) {
$mt = $object->getMTime();
if (!$ignoreDir && $object->isFile() && !isset($o->{$fileName}) && !file_exists($this->pd . "/" . $fileName)) {
$o->{$fileName} = $mt;
$this->moveStaticFile($fileName, "added");
if ($object->getExtension() == "css") {
$this->updateSite($fileName, "changed", 0);
// make sure the site is updated for MQ reasons
}
} else {
if (!$ignoreDir && $object->isFile() && isset($o->{$fileName}) && $o->{$fileName} != $mt) {
$o->{$fileName} = $mt;
$this->moveStaticFile($fileName, "changed");
if ($object->getExtension() == "css") {
$this->updateSite($fileName, "changed", 0);
// make sure the site is updated for MQ reasons
}
} else {
if (!isset($o->fileName)) {
$o->{$fileName} = $mt;
}
}
}
} else {
unset($o->{$fileName});
}
}
}
}
$c = true;
// taking out the garbage. basically killing mustache after each run.
unset($this->mpl);
unset($this->msf);
unset($this->mv);
if (gc_enabled()) {
gc_collect_cycles();
}
// output anything the reload server might send our way
if ($reload) {
$output = fgets($fp, 100);
if ($output != "\n") {
print $output;
}
}
// pause for .05 seconds to give the CPU a rest
usleep(50000);
}
// close the auto-reload process, this shouldn't do anything
fclose($fp);
}
开发者ID:beingsane,项目名称:patternlab-php,代码行数:101,代码来源:Watcher.php
注:本文中的gc_enabled函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论