本文整理汇总了PHP中increase_memory_limit_to函数的典型用法代码示例。如果您正苦于以下问题:PHP increase_memory_limit_to函数的具体用法?PHP increase_memory_limit_to怎么用?PHP increase_memory_limit_to使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了increase_memory_limit_to函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Load the given file via {@link self::processAll()} and {@link self::processRecord()}.
* Optionally truncates (clear) the table before it imports.
*
* @param string $filepath The filepath to use
*
* @return BulkLoader_Result See {@link self::processAll()}
*
* @author Sascha Koehler <skoehler@pixeltricks.de>
* @since 20.07.2011
*/
public function load($filepath)
{
if (!SilvercartPlugin::call($this, 'overwriteLoad', array($filepath), false, 'DataObject')) {
ini_set('max_execution_time', 3600);
increase_memory_limit_to('256M');
//get all instances of the to be imported data object
if ($this->deleteExistingRecords) {
$q = singleton($this->objectClass)->buildSQL();
if (!empty($this->objectClass)) {
$idSelector = $this->objectClass . '."ID"';
} else {
$idSelector = '"ID"';
}
$q->select = array($idSelector);
$ids = $q->execute()->column('ID');
foreach ($ids as $id) {
$obj = DataObject::get_by_id($this->objectClass, $id);
$obj->delete();
$obj->destroy();
unset($obj);
}
}
return $this->processAll($filepath);
}
}
示例2: collectChanges
/**
* Collect all changes for the given context.
*/
public function collectChanges($context)
{
increase_time_limit_to();
increase_memory_limit_to();
if (is_callable(array($this->owner, 'objectsToUpdate'))) {
$toUpdate = $this->owner->objectsToUpdate($context);
if ($toUpdate) {
foreach ($toUpdate as $object) {
if (!is_callable(array($this->owner, 'urlsToCache'))) {
continue;
}
$urls = $object->urlsToCache();
if (!empty($urls)) {
$this->toUpdate = array_merge($this->toUpdate, $this->owner->getUrlArrayObject()->addObjects($urls, $object));
}
}
}
}
if (is_callable(array($this->owner, 'objectsToDelete'))) {
$toDelete = $this->owner->objectsToDelete($context);
if ($toDelete) {
foreach ($toDelete as $object) {
if (!is_callable(array($this->owner, 'urlsToCache'))) {
continue;
}
$urls = $object->urlsToCache();
if (!empty($urls)) {
$this->toDelete = array_merge($this->toDelete, $this->owner->getUrlArrayObject()->addObjects($urls, $object));
}
}
}
}
}
示例3: testIncreaseMemoryLimitTo
function testIncreaseMemoryLimitTo() {
if(!$this->canChangeMemory()) return;
ini_set('memory_limit', '64M');
// It can go up
increase_memory_limit_to('128M');
$this->assertEquals('128M', ini_get('memory_limit'));
// But not down
increase_memory_limit_to('64M');
$this->assertEquals('128M', ini_get('memory_limit'));
// Test the different kinds of syntaxes
increase_memory_limit_to(1024*1024*200);
$this->assertEquals(1024*1024*200, ini_get('memory_limit'));
increase_memory_limit_to('409600K');
$this->assertEquals('409600K', ini_get('memory_limit'));
increase_memory_limit_to('1G');
// If memory limit was left at 409600K, that means that the current testbox doesn't have
// 1G of memory available. That's okay; let's not report a failure for that.
if(ini_get('memory_limit') != '409600K') {
$this->assertEquals('1G', ini_get('memory_limit'));
}
// No argument means unlimited
increase_memory_limit_to();
$this->assertEquals(-1, ini_get('memory_limit'));
}
示例4: run
/**
* Perform migration
*
* @param string $base Absolute base path (parent of assets folder). Will default to BASE_PATH
* @return int Number of files successfully migrated
*/
public function run($base = null)
{
if (empty($base)) {
$base = BASE_PATH;
}
// Check if the File dataobject has a "Filename" field.
// If not, cannot migrate
if (!DB::get_schema()->hasField('File', 'Filename')) {
return 0;
}
// Set max time and memory limit
increase_time_limit_to();
increase_memory_limit_to();
// Loop over all files
$count = 0;
$filenameMap = $this->getFilenameArray();
foreach ($this->getFileQuery() as $file) {
// Get the name of the file to import
$filename = $filenameMap[$file->ID];
$success = $this->migrateFile($base, $file, $filename);
if ($success) {
$count++;
}
}
return $count;
}
示例5: fire
public function fire()
{
increase_memory_limit_to();
increase_time_limit_to();
/** @var i18nTextCollector $collector */
$collector = i18nTextCollector::create($this->option('locale'));
if (!$this->option('locale')) {
$this->info('Starting text collection. No Locale specified');
} else {
$this->info('Starting text collection for: ' . $this->option('locale'));
}
$merge = $this->getIsMerge();
if ($merge) {
$this->info('New strings will be merged with existing strings');
}
// Custom writer
$writerName = $this->option('writer');
if ($writerName) {
$writer = Injector::inst()->get($writerName);
$collector->setWriter($writer);
$this->info('Set collector writer to: ' . $writer);
}
// Get restrictions
$restrictModules = $this->option('module') ? explode(',', $this->option('module')) : null;
$this->info('Collecting in modules: ' . $this->option('module'));
// hack untill we have something better
ob_start();
$collector->run($restrictModules, $merge);
$this->warn(ob_get_contents());
ob_get_clean();
$this->info(__CLASS__ . ' completed!');
}
示例6: __construct
/**
* @param Config_ForClass $config
*/
public function __construct(Config_ForClass $config = null)
{
parent::__construct();
$this->config = $config ?: Config::inst()->forClass(__CLASS__);
if ($memLimit = $this->config->get('memory')) {
increase_memory_limit_to($memLimit);
}
}
示例7: load
/**
* Load the given file via {@link self::processAll()} and {@link self::processRecord()}.
* Optionally truncates (clear) the table before it imports.
*
* @return BulkLoader_Result See {@link self::processAll()}
*/
public function load($filepath)
{
// A small hack to allow model admin import form to work properly
if (!is_array($filepath) && isset($_FILES['_CsvFile'])) {
$filepath = $_FILES['_CsvFile'];
}
if (is_array($filepath)) {
$this->uploadFile = $filepath;
$filepath = $filepath['tmp_name'];
}
increase_time_limit_to();
increase_memory_limit_to('512M');
//get all instances of the to be imported data object
if ($this->deleteExistingRecords) {
DataObject::get($this->objectClass)->removeAll();
}
return $this->processAll($filepath);
}
示例8: testIncreaseMemoryLimitTo
function testIncreaseMemoryLimitTo()
{
ini_set('memory_limit', '64M');
// It can go up
increase_memory_limit_to('128M');
$this->assertEquals('128M', ini_get('memory_limit'));
// But not down
increase_memory_limit_to('64M');
$this->assertEquals('128M', ini_get('memory_limit'));
// Test the different kinds of syntaxes
increase_memory_limit_to(1024 * 1024 * 200);
$this->assertEquals(1024 * 1024 * 200, ini_get('memory_limit'));
increase_memory_limit_to('409600K');
$this->assertEquals('409600K', ini_get('memory_limit'));
increase_memory_limit_to('1G');
$this->assertEquals('1G', ini_get('memory_limit'));
// No argument means unlimited
increase_memory_limit_to();
$this->assertEquals(-1, ini_get('memory_limit'));
}
示例9: run
public function run($request)
{
set_time_limit(0);
increase_memory_limit_to();
Subsite::$disable_subsite_filter = true;
$mainConfig = SiteConfig::current_site_config();
$mainConfig->compileStyles();
DB::alteration_message("Compile styles for main site");
$subsites = Subsite::get();
foreach ($subsites as $subsite) {
$subsiteConfig = SiteConfig::get()->filter('SubsiteID', $subsite->ID)->first();
if (!$subsiteConfig) {
DB::alteration_message("No config for subsite " . $subsite->ID, "error");
continue;
}
$subsiteConfig->compileStyles();
DB::alteration_message("Compile styles for subsite " . $subsite->ID);
}
DB::alteration_message("All done");
}
示例10: publishPages
/**
* Uses {@link Director::test()} to perform in-memory HTTP requests
* on the passed-in URLs.
*
* @param array $urls Relative URLs
* @return array Result, keyed by URL. Keys:
* - "statuscode": The HTTP status code
* - "redirect": A redirect location (if applicable)
* - "path": The filesystem path where the cache has been written
*/
public function publishPages($urls)
{
$result = array();
//nest the config so we can make changes to the config and revert easily
Config::nest();
// Do we need to map these?
// Detect a numerically indexed arrays
if (is_numeric(join('', array_keys($urls)))) {
$urls = $this->urlsToPaths($urls);
}
// This can be quite memory hungry and time-consuming
// @todo - Make a more memory efficient publisher
increase_time_limit_to();
increase_memory_limit_to();
// Set the appropriate theme for this publication batch.
// This may have been set explicitly via StaticPublisher::static_publisher_theme,
// or we can use the last non-null theme.
$customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme');
if ($customTheme) {
Config::inst()->update('SSViewer', 'theme', $customTheme);
}
// Ensure that the theme that is set gets used.
Config::inst()->update('SSViewer', 'theme_enabled', true);
$staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url');
if ($staticBaseUrl) {
Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl);
}
if ($this->fileExtension == 'php') {
Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php');
}
if (Config::inst()->get('StaticPublisher', 'echo_progress')) {
echo $this->class . ": Publishing to " . $staticBaseUrl . "\n";
}
$files = array();
$i = 0;
$totalURLs = sizeof($urls);
foreach ($urls as $url => $path) {
$origUrl = $url;
$result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null);
$i++;
if ($url && !is_string($url)) {
user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
continue;
}
if (Config::inst()->get('StaticPublisher', 'echo_progress')) {
echo " * Publishing page {$i}/{$totalURLs}: {$url}\n";
flush();
}
Requirements::clear();
if ($url == "") {
$url = "/";
}
if (Director::is_relative_url($url)) {
$url = Director::absoluteURL($url);
}
$response = Director::test(str_replace('+', ' ', $url));
if (!$response) {
continue;
}
if ($response) {
$result[$origUrl]['statuscode'] = $response->getStatusCode();
}
Requirements::clear();
singleton('DataObject')->flushCache();
// Check for ErrorPages generating output - we want to handle this in a special way below.
$isErrorPage = false;
$pageObject = null;
if ($response && is_object($response) && (int) $response->getStatusCode() >= 400) {
$pageObject = SiteTree::get_by_link($url);
if ($pageObject && $pageObject instanceof ErrorPage) {
$isErrorPage = true;
}
}
// Skip any responses with a 404 status code unless it's the ErrorPage itself.
if (!$isErrorPage && is_object($response) && $response->getStatusCode() == '404') {
continue;
}
// Generate file content
// PHP file caching will generate a simple script from a template
if ($this->fileExtension == 'php') {
if (is_object($response)) {
if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
$content = $this->generatePHPCacheRedirection($response->getHeader('Location'));
} else {
$content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
}
} else {
$content = $this->generatePHPCacheFile($response . '', HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
}
// HTML file caching generally just creates a simple file
//.........这里部分代码省略.........
示例11: load
public function load($filepath)
{
ini_set('max_execution_time', 3600);
increase_memory_limit_to('512M');
//get all instances of the to be imported data object
if ($this->deleteExistingRecords) {
$q = singleton($this->objectClass)->buildSQL();
$q->select = array('"ID"');
$ids = $q->execute()->column('ID');
foreach ($ids as $id) {
$obj = DataObject::get_by_id($this->objectClass, $id);
$obj->delete();
$obj->destroy();
unset($obj);
}
}
return $this->processAll($filepath);
}
示例12: publishPages
/**
* Uses {@link Director::test()} to perform in-memory HTTP requests
* on the passed-in URLs.
*
* @param array $urls Relative URLs
* @return array Result, keyed by URL. Keys:
* - "statuscode": The HTTP status code
* - "redirect": A redirect location (if applicable)
* - "path": The filesystem path where the cache has been written
*/
public function publishPages($urls)
{
$result = array();
// Do we need to map these?
// Detect a numerically indexed arrays
if (is_numeric(join('', array_keys($urls)))) {
$urls = $this->urlsToPaths($urls);
}
// This can be quite memory hungry and time-consuming
// @todo - Make a more memory efficient publisher
increase_time_limit_to();
increase_memory_limit_to();
Config::inst()->nest();
// Set the appropriate theme for this publication batch.
// This may have been set explicitly via StaticPublisher::static_publisher_theme,
// or we can use the last non-null theme.
$customTheme = Config::inst()->get('FilesystemPublisher', 'static_publisher_theme');
if ($customTheme) {
Config::inst()->update('SSViewer', 'theme', $customTheme);
}
// Ensure that the theme that is set gets used.
Config::inst()->update('SSViewer', 'theme_enabled', true);
$currentBaseURL = Director::baseURL();
$staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url');
if ($this->fileExtension == 'php') {
Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php');
}
if (Config::inst()->get('FilesystemPublisher', 'echo_progress')) {
echo $this->class . ": Publishing to " . $staticBaseUrl . "\n";
}
$files = array();
$i = 0;
$totalURLs = sizeof($urls);
foreach ($urls as $url => $path) {
$origUrl = $url;
$result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null);
$i++;
if ($url && !is_string($url)) {
user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
continue;
}
if (Config::inst()->get('FilesystemPublisher', 'echo_progress')) {
echo " * Publishing page {$i}/{$totalURLs}: {$url}\n";
flush();
}
Requirements::clear();
if ($url == "") {
$url = "/";
}
if (Director::is_relative_url($url)) {
$url = Director::absoluteURL($url);
}
$sanitizedURL = URLArrayObject::sanitize_url($url);
$response = Director::test(str_replace('+', ' ', $sanitizedURL));
// Prevent empty static cache files from being written
if (is_object($response) && !$response->getBody()) {
SS_Log::log(new Exception('Prevented blank static cache page write for: ' . $path), SS_Log::NOTICE);
continue;
}
if (!$response) {
continue;
}
if ($response) {
$result[$origUrl]['statuscode'] = $response->getStatusCode();
}
Requirements::clear();
singleton('DataObject')->flushCache();
// Check for ErrorPages generating output - we want to handle this in a special way below.
$isErrorPage = false;
$pageObject = null;
if ($response && is_object($response) && (int) $response->getStatusCode() >= 400) {
$obj = $this->owner->getUrlArrayObject()->getObject($url);
if ($obj && $obj instanceof ErrorPage) {
$isErrorPage = true;
}
}
// Skip any responses with a 404 status code unless it's the ErrorPage itself.
if (!$isErrorPage && is_object($response) && $response->getStatusCode() == '404') {
continue;
}
// Generate file content.
// PHP file caching will generate a simple script from a template
if ($this->fileExtension == 'php') {
if (is_object($response)) {
if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
$content = $this->generatePHPCacheRedirection($response->getHeader('Location'));
} else {
$content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
}
} else {
//.........这里部分代码省略.........
示例13: process
public function process()
{
self::$config = $this->config();
if (!self::$config->wkHtmlToPdfPath) {
throw new Exception("You must provide a path for WkHtmlToPdf in your sites configuration.");
}
if (!self::$config->emailAddress) {
throw new Exception("You must provide an email address to send from in your sites configuration.");
}
increase_memory_limit_to('1024M');
set_time_limit(0);
$sites = LinkCheckSite::get();
$outputDir = BASE_PATH . DIRECTORY_SEPARATOR . "silverstripe-linkcheck/runs/";
$filesCreated = array();
// build the crawler
chdir(__DIR__ . "/../thirdparty");
exec("javac " . self::$crawler . " " . self::$linkStats . " && " . "javac " . self::$linkProject);
if ($sites) {
foreach ($sites as $site) {
echo "Checking " . $site->SiteURL . "\r\n";
$url = $site->SiteURL;
// if the output directory doesn't exist for the run, create it
if (!file_exists($outputDir . str_replace("http://", "", $url))) {
mkdir($outputDir . str_replace("http://", "", $url));
}
$filename = date("Y-m-d") . '-' . rand(0, 1000) . ".html";
$filepath = $outputDir . str_replace("http://", "", $url) . '/';
// execute the crawler
exec("java Project {$url} " . $filepath . $filename . " 10 1000");
$filesCreated[$site->ID]['FilePath'] = $filepath;
$filesCreated[$site->ID]['FileName'] = $filename;
$filesCreated[$site->ID]['SiteName'] = $site->SiteName;
$filesCreated[$site->ID]['ID'] = $site->ID;
$filesCreated[$site->ID]['URL'] = $url;
$emailRecipients = $site->EmailRecipients();
if ($emailRecipients) {
foreach ($emailRecipients as $recipient) {
$filesCreated[$site->ID]['Email'][] = $recipient->Email;
}
}
}
foreach ($filesCreated as $file) {
Folder::find_or_make("LinkCheck" . DIRECTORY_SEPARATOR . $file['SiteName'] . DIRECTORY_SEPARATOR);
$pdfPath = "assets" . DIRECTORY_SEPARATOR . "LinkCheck" . DIRECTORY_SEPARATOR . $file['SiteName'] . DIRECTORY_SEPARATOR;
$pdfFullPath = BASE_PATH . DIRECTORY_SEPARATOR . $pdfPath;
$pdfName = str_replace("html", "pdf", $file['FileName']);
$generator = new WkHtml\Generator(new \Knp\Snappy\Pdf(self::$config->wkHtmlToPdfPath), new WkHtml\Input\String(file_get_contents($file['FilePath'] . $file['FileName'])), new WkHtml\Output\File($pdfFullPath . $pdfName, 'application/pdf'));
$generator->process();
$site = LinkCheckSite::get()->byID($file['ID']);
$pdfUpload = new File();
$pdfUpload->Title = $file['SiteName'] . '-' . $pdfName;
$pdfUpload->Filename = $pdfPath . $pdfName;
$pdfUpload->write();
$linkCheckRun = new LinkCheckRun();
$linkCheckRun->LinkCheckFileID = $pdfUpload->ID;
$linkCheckRun->LinkCheckSiteID = $site->ID;
$linkCheckRun->write();
$site->LinkCheckRuns()->add($linkCheckRun);
foreach ($file['Email'] as $emailAddress) {
$email = new Email();
$email->to = $emailAddress;
$email->from = $this->config()->emailAddress;
$email->subject = $file['SiteName'] . " link check run";
$email->body = "Site Link Check Run for {$file['URL']} on " . date("Y/m/d");
$email->attachFile($pdfPath . $pdfName, "linkcheck.pdf");
$email->send();
}
unlink($file['FilePath'] . $file['FileName']);
}
}
}
示例14: define
/**
* Define the temporary folder if it wasn't defined yet
*/
if (!defined('TEMP_FOLDER')) {
define('TEMP_FOLDER', getTempFolder());
}
/**
* Priorities definition. These constants are used in calls to _t() as an optional argument
*/
define('PR_HIGH', 100);
define('PR_MEDIUM', 50);
define('PR_LOW', 10);
/**
* Ensure we have enough memory
*/
increase_memory_limit_to('64M');
///////////////////////////////////////////////////////////////////////////////
// INCLUDES
require_once "core/ManifestBuilder.php";
require_once "core/ClassInfo.php";
require_once 'core/Object.php';
require_once 'core/control/Director.php';
require_once 'filesystem/Filesystem.php';
require_once "core/Session.php";
///////////////////////////////////////////////////////////////////////////////
// MANIFEST
/**
* Include the manifest
*/
ManifestBuilder::include_manifest();
/**
示例15: index
/**
* Either creates or updates a record in the index.
*
* @param Searchable $record
* @return \Elastica\Response
*/
public function index($record)
{
if (!$this->indexingMemorySet && $this->indexingMemory) {
if ($this->indexingMemory == 'unlimited') {
increase_memory_limit_to();
} else {
increase_memory_limit_to($this->indexingMemory);
}
$this->indexingMemorySet = true;
}
try {
$document = $record->getElasticaDocument();
$type = $record->getElasticaType();
$index = $this->getIndex();
$response = $index->getType($type)->addDocument($document);
$index->refresh();
return $response;
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->warning($e->getMessage());
}
}
}