$value) { $lines .= $name . ': ' . $value . "\r\n"; } $context = stream_context_create(['http' => [ 'method' => 'GET', 'header' => $lines, 'timeout' => $timeout, 'ignore_errors' => true, ]]); $body = @file_get_contents($url, false, $context); if ($body === false) { throw new NetworkException('could not reach ' . $url); } $status = 0; $received = []; foreach ($http_response_header ?? [] as $line) { if (preg_match('#^HTTP/\S+\s+(\d{3})#', $line, $match) === 1) { $status = (int) $match[1]; continue; } $parts = explode(':', $line, 2); if (count($parts) === 2) { $received[trim($parts[0])][] = trim($parts[1]); } } return new Response($status, $received, $body); } }