SilverStripe 4 - large asset downloads exhausts memory_limit in HTTPStreamResponse.php

Asked
Active3 hr before
Viewed126 times

3 Answers

90%

Relating to this issue raised https://stackoverflow.com/questions/57085714/silverstripe-4-large-asset-downloads-exhausts-memory-limit-in-httpstreamrespon,I am thinking this might be a problem when the class is used to stream a non-video/audio file, such as serving a download stream for an archive/document.,Also the hash is computed by reading a stream. So we shouldn't need to load the entire file in memory at once to do it. https://github.com/silverstripe/silverstripe-assets/blob/fc17276f93c6a5110fbe91e0796d4f0051c1c482/src/Storage/Sha1FileHashingService.php#L49-L57,Yes it does look like its missing the conventional “loop and read N bytes, flush buffer” thing that i normally see when outputting streams

public
function getBody() {
   $body = $this - > getSavedBody();
   if (isset($body)) {
      return $body;
   }
   // Consume stream into string
   $body = $this - > consumeStream(function($stream) {
      $body = stream_get_contents($stream);
      // If this stream isn't seekable, we'll need to save the body
      // in case of subsequent requests.
      if (!$this - > isSeekable()) {
         $this - > setBody($body); // <---------------
      }
      return $body;
   });
   return $body;
}
load more v
88%

I don’t know what level of control you have over the configuration, but really you need to increase the PHP memory limit for the site. Hopefully this will make all the image issues go away.,Thanks @DorsetDigital, I can try increasing the memory limit - is there a recommended value? Currently it is set, I believe, to 128M.,Thanks DorsetDigital, I’ve marked your reply as the solution as the issue seems to have gone away for my client, so it does the job. Thanks for your help.,This error might also have to do with the actual pixelsize of the image more then the bytesize, because that is the crux in creating thumbnails.

Don’t know why it’s different error messages, the full error for file 2 is:

ERROR[Alert]: Allowed memory size of 134217728 bytes exhausted(tried to allocate 34560001 bytes)
IN POST / admin / assets / api / createFile
Line 80 in /home/cluster - sites / 4 / l / littlemonsterspreloved.co.uk / public_html / vendor / intervention / image / src / Intervention / Image / Gd / Driver.php

Source
   ===
   ===
   71: * /
72: public
function cloneCore($core)
73: {
   74: $width = imagesx($core);
   75: $height = imagesy($core);
   76: $clone = imagecreatetruecolor($width, $height);
   77: imagealphablending($clone, false);
   78: imagesavealpha($clone, true);
   79: $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127);
   * 80: imagefill($clone, 0, 0, $transparency);
   81: 82: imagecopy($clone, $core, 0, 0, 0, 0, $width, $height);
   83: 84: return $clone;
   85:
}
86:
}
load more v
72%

Acts as the primary store for environment variables, including those loaded from .env files. Applications should use Environment::getEnv() instead of php's getenv in order to include .env configuration, as the system's actual environment variables are treated immutably.,Value of the environment variable, or false if not set,Get value of environment variable,Set environment variable using php.ini syntax.

This class should be used sparingly, and only if information cannot be obtained from a current {@link HTTPRequest} object.

Acts as the primary store for environment variables, including those loaded from .env files. Applications should use Environment::getEnv() instead of php's getenv in order to include .env configuration, as the system's actual environment variables are treated immutably.

getenv

This class should be used sparingly, and only if information cannot be obtained from a current {@link HTTPRequest} object.

Acts as the primary store for environment variables, including those loaded from .env files. Applications should use Environment::getEnv() instead of php's getenv in order to include .env configuration, as the system's actual environment variables are treated immutably.

.env
load more v

Other "undefined-undefined" queries related to "SilverStripe 4 - large asset downloads exhausts memory_limit in HTTPStreamResponse.php"