This section provides a tutorial example script, HttpRequestGet.php, on how to dump the entire HTTP response including all header lines from a Web server.
When a client program receives an HTTP response, it will look at header lines
first. Based on the information contained in header lines, the client program will
decide what to do with the actual response data in the entity body.
If you use a Web browser as an HTTP client program, it will process the data
in the entity body differently depending on mainly the "Content-Type" entity header line:
displaying the data as it is,
rendering the data as an HTML document and displaying the resulting information,
or passing the data to another registered program to handle it.
Once the Web browser finishes processing the entity body, you can get some limited information
from the header lines. For example, you can click the right mouse button and select
the properties command on Internet Explorer, it will display some general properties
about this response in a pop up window. Properties displayed are not always
identical to response header lines. The "Modified" property is probably identical
to the "Last-Modified" entity header line. The "Type" property is sometime related
to the "Content-Type" entity header line, and sometimes related to server side resource
that generated the response.
How to view all header lines received in an HTTP response? I couldn't easily find
any existing tools to do this. So I wrote the following program to dump the entire
response including all header lines received from a Web server:
$argv is built-in array that contains all command line arguments, with $argv[0] representing
the PHP file name, if you run your PHP file as "php file_name.php ...".
You need to make sure that "extension=php_sockets.dll" is turned on in your php.ini configuration file
to use socket related functions.