Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Added low memory option. Fixes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
straube committed Oct 26, 2019
1 parent f3b1afd commit d6e3c04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Since `0.7.1` this project adheres to

## [Unreleased]

### Added

* Low memory option. ([#45])

### Fixed

* Fixed variable names starting with `MULTPLE_`, changed to `MULTIPLE`.
Expand Down Expand Up @@ -293,6 +297,7 @@ e.g.
[#55]: https://github.com/straube/multiple-domain/issues/55
[#51]: https://github.com/straube/multiple-domain/issues/51
[#50]: https://github.com/straube/multiple-domain/issues/50
[#45]: https://github.com/straube/multiple-domain/issues/45
[#44]: https://github.com/straube/multiple-domain/issues/44
[#42]: https://github.com/straube/multiple-domain/issues/42
[#39]: https://github.com/straube/multiple-domain/issues/39
Expand Down
5 changes: 4 additions & 1 deletion multiple-domain/MultipleDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ private function getDomainAttribute($name, $domain = null)
*/
private function replaceDomain($domain, $content)
{
if (MULTIPLE_DOMAIN_LOW_MEMORY) {
return $this->replaceDomainUsingLessMemory($domain, $content);
}
if (array_key_exists($domain, $this->domains)) {
$regex = '/(https?):\/\/' . preg_quote($domain, '/') . '(?![a-z0-9.\-:])/i';
$protocol = $this->getDomainProtocol($this->domain);
Expand All @@ -825,7 +828,7 @@ private function replaceDomainUsingLessMemory($domain, $content)
$regex = '(https?):\/\/' . preg_quote($domain, '/') . '(?![a-z0-9.\-:])';
$protocol = $this->getDomainProtocol($this->domain);
$replace = ($protocol === 'auto' ? '\\1' : $protocol) . '://' . $this->domain;
$content = preg_replace($regex, $replace, $content);
$content = mb_eregi_replace($regex, $replace, $content);
}
return $content;
}
Expand Down
14 changes: 14 additions & 0 deletions multiple-domain/multiple-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
*/
define('MULTIPLE_DOMAIN_PLUGIN', __FILE__);

if (!defined('MULTIPLE_DOMAIN_LOW_MEMORY')) {

/**
* The low memory option.
*
* This option may be used where the site is throwing "allowed memory
* exhausted" errors. It will reduce the memory usage in domain replacements
* with the downside of a higher execution time.
*
* @var bool
*/
define('MULTIPLE_DOMAIN_LOW_MEMORY', false);
}


/*
* Register the activation method.
Expand Down

0 comments on commit d6e3c04

Please sign in to comment.