$value) { $lines[] = $name . ': ' . $value; } $milliseconds = max(1, (int) round($timeout * 1000)); $received = []; curl_setopt_array($handle, [ CURLOPT_URL => $url, CURLOPT_HTTPGET => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $lines, CURLOPT_CONNECTTIMEOUT_MS => $milliseconds, CURLOPT_TIMEOUT_MS => $milliseconds, CURLOPT_FOLLOWLOCATION => $this->maxRedirects > 0, CURLOPT_MAXREDIRS => $this->maxRedirects, CURLOPT_SSL_VERIFYPEER => $this->verifyTls, CURLOPT_SSL_VERIFYHOST => $this->verifyTls ? 2 : 0, CURLOPT_NOSIGNAL => true, CURLOPT_HEADERFUNCTION => static function ($_handle, string $line) use (&$received): int { $length = strlen($line); $parts = explode(':', $line, 2); if (count($parts) === 2) { $received[trim($parts[0])][] = trim($parts[1]); } return $length; }, ]); $body = curl_exec($handle); $error = curl_error($handle); $status = (int) curl_getinfo($handle, CURLINFO_RESPONSE_CODE); unset($handle); if ($body === false || $status === 0) { throw new NetworkException(sprintf( 'could not reach %s: %s', $url, $error !== '' ? $error : 'the request did not complete', )); } return new Response($status, $received, (string) $body); } }