41 private string $method = self::METHOD_FPASSTHRU;
53 $ini_memory_limit = ini_get(
'memory_limit');
55 if (preg_match(
'/^(\d+)(.)$/', $ini_memory_limit, $matches)) {
56 $memory_limit = match ($matches[2] ??
null) {
57 'G' => (
int) $matches[1] * 1024 * 1024 * 1024,
58 'M' => (
int) $matches[1] * 1024 * 1024,
59 'K' => (
int) $matches[1] * 1024,
60 default => (
int) $matches[1],
64 return $memory_limit ?? 128 * 1024 * 1024;
69 return (
int) round(max($this->memory_limit / 4, 8 * 1024));
87 http_response_code($response->getStatusCode());
90 foreach (array_keys($response->getHeaders()) as $key) {
92 if (strtolower($key) ===
'set-cookie') {
93 foreach ($response->getHeader($key) as $header) {
94 header(
"$key: " . $header,
false);
97 header(
"$key: " . $response->getHeaderLine($key));
102 $stream = $response->getBody();
106 $body_size = $stream->getSize();
107 if ($body_size > $this->memory_limit) {
108 $this->method = self::METHOD_READFILE;
112 $resource = $stream->detach();
116 if (is_resource($resource)) {
122 switch ($this->method) {
123 case self::METHOD_FPASSTHRU:
124 $sendStatus = fpassthru($resource);
126 case self::METHOD_READFILE:
129 while (!feof($resource)) {
130 echo $return = fread($resource, $this->chunk_size);
131 $sendStatus = $sendStatus && $return !==
false;
142 if ($sendStatus ===
false) {
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Interface ResponseSenderStrategy.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class DefaultResponseSenderStrategy.