Sending Request with Close Connection Header [PHP Code]

The "Connection: close" HTTP header informs the server that the client wants to close the connection after completing the HTTP transaction. The server decides whether to close the connection after the request or not. In this Connection Close header example, we send a GET request to the ReqBin echo URL with the "Connection: close" HTTP header. Click Send to execute the Close Connection example online and see the results. The PHP code was automatically generated for the Close Connection example.
Sending Request with Close Connection Header [PHP Code] Send
GET /echo HTTP/1.1
Host: reqbin.com
Connection: close

Updated: Viewed: 11658 times
PHP code for Close Connection example

PHP code for Close Connection Example

This PHP code snippet was generated automatically for the Close Connection example.
<< Back to the Close Connection example

What are HTTP Headers?

An HTTP request or response consists of HTTP headers and an HTTP body. HTTP headers contain a case-insensitive name, a colon (:), and a header value. A header field comprises a case-insensitive name followed by a colon (':') and its value (spaces between name and value are ignored). The server uses HTTP headers to send data type information and size in the response body, compression method used, caching directives, and cross-origin resource sharing restrictions (CORS).

What is an HTTP connection header?

HTTP Connection headers are general-purpose headers that allow the sender or client to specify the parameters required for that particular connection. You can send or receive multiple HTTP requests and responses using a single TCP connection instead of opening a new connection for each request. HTTP Connection also controls whether the network remains open or closed after completing the current transaction.

Close Connection Header Syntax

The following is the syntax of the Closed Connection header:

HTTP Connection Close Syntax
Connection: close

Close Connection Example

The following is an example of sending a GET request with a Closed Connection header:

Close Connection Example
GET /echo HTTP/1.1
Host: reqbin.com
Connection: close

Server response to our request:

Server Response Example
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Connection: close

See also

Generate code snippets for PHP and other programming languages

Convert your Close Connection request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the PHP code generator.