40 $this->method = self::METHOD_FPASSTHRU;
45 $ini_memory_limit = ini_get(
'memory_limit');
47 if (preg_match(
'/^(\d+)(.)$/', $ini_memory_limit, $matches)) {
48 switch (($matches[2] ?? null)) {
50 $memory_limit = (
int) $matches[1] * 1024 * 1024 * 1024;
53 $memory_limit = (
int) $matches[1] * 1024 * 1024;
56 $memory_limit = (
int) $matches[1] * 1024;
59 $memory_limit = (
int) $matches[1];
63 return $memory_limit ?? 128 * 1024 * 1024;
68 return (
int) round(max($this->memory_limit / 4, 8 * 1024));
86 http_response_code($response->getStatusCode());
89 foreach (array_keys($response->getHeaders()) as
$key) {
91 if (strtolower($key) ===
'set-cookie') {
92 foreach ($response->getHeader($key) as $header) {
93 header(
"$key: " . $header,
false);
96 header(
"$key: " . $response->getHeaderLine($key));
101 $stream = $response->getBody();
105 $body_size = $stream->getSize();
106 if ($body_size > $this->memory_limit) {
107 $this->method = self::METHOD_READFILE;
111 $resource = $stream->detach();
115 if (is_resource($resource)) {
121 switch ($this->method) {
122 case self::METHOD_FPASSTHRU:
123 $sendStatus = fpassthru($resource);
125 case self::METHOD_READFILE:
128 while (!feof($resource)) {
129 echo $return = fread($resource, $this->chunk_size);
130 $sendStatus = $sendStatus && $return !==
false;
141 if ($sendStatus ===
false) {
Interface ResponseSenderStrategy.
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
Class DefaultResponseSenderStrategy.