diff --git a/core/startup/ErrorControlChain.php b/core/startup/ErrorControlChain.php
index dc32257e7..4ac510cbb 100644
--- a/core/startup/ErrorControlChain.php
+++ b/core/startup/ErrorControlChain.php
@@ -74,9 +74,33 @@ class ErrorControlChain {
return $error && ($error['type'] & self::$fatal_errors) != 0;
}
+ protected function lastErrorWasMemoryExhaustion() {
+ $error = error_get_last();
+ $message = $error ? $error['message'] : '';
+ return stripos($message, 'memory') !== false && stripos($message, 'exhausted') !== false;
+ }
+
+ static $transtable = array(
+ 'k' => 1024,
+ 'm' => 1048576,
+ 'g' => 1073741824
+ );
+
+ protected function translateMemstring($memString) {
+ $char = strtolower(substr($memString, -1));
+ $fact = isset(self::$transtable[$char]) ? self::$transtable[$char] : 1;
+ return ((int)$memString) * $fact;
+ }
+
public function handleFatalError() {
if ($this->handleFatalErrors && $this->suppression) {
if ($this->lastErrorWasFatal()) {
+ if ($this->lastErrorWasMemoryExhaustion()) {
+ // Bump up memory limit by an arbitrary 10% / 10MB (whichever is bigger) since we've run out
+ $cur = $this->translateMemstring(ini_get('memory_limit'));
+ if ($cur != -1) ini_set('memory_limit', $cur + max(round($cur*0.1), 10000000));
+ }
+
$this->error = true;
$this->step();
}
diff --git a/core/startup/ParameterConfirmationToken.php b/core/startup/ParameterConfirmationToken.php
index 21364f871..fe85d293f 100644
--- a/core/startup/ParameterConfirmationToken.php
+++ b/core/startup/ParameterConfirmationToken.php
@@ -94,7 +94,14 @@ class ParameterConfirmationToken {
$location = "$proto://" . $host . BASE_URL . $url . ($params ? '?'.http_build_query($params) : '');
// And redirect
- header('location: '.$location, true, 302);
+ if (headers_sent()) {
+ echo "
+
+
+You are being redirected. If you are not redirected soon, click here to continue the flush
+";
+ }
+ else header('location: '.$location, true, 302);
die;
}
}