HTTP Connection class
Instance of this class represents a connection to a HTTP server.
This class is experimental.
Example:
1 $http =& new HTTP_Connection('stopwar.org.uk', 80, 10, 30, array('max_header_lines'=>50));
2 // 1st argument: host
3 // 2nd argument: optioanl - port (default: 80)
4 // 3rd argument: optional - connection timeout
5 // 4th argument: optional - read/write timeout
6 // 5th argument: optional - options (at the moment, it's only 'max_header_lines' and
7
See test_HTTP_Connection.php for more examples
TODO:
Located in Program_Root/HTTP_Connection.php (line 51)
Last error number
Last error string
Maximum header lines
Maximum header line length.
Setting this to 0 indicates no limit on the length
Socket (result of fsockopen())
Constructor
Example:
headers object
message body
EOF
Tests for end-of-file. If a server keeps the connection open (e.g. if there's no "Connection: close" header in the response), eof() will return false even if you've read the whole response.
Format as chunk (support for reading chunked responses is required by HTTP/1.1)
Get unread bytes - the number of bytes currently contained in the read buffer.
Read
Like builtin fread(): reads up to length bytes. Reading stops when length bytes have been read or EOF (end of file) reached, whichever comes first.
Read chunk
If a chunk is recognised, an array will be returned holding chunk data and the chunk size. Otherwise a string will be returned holding the result of read_line().
Example:
1 $chunk = $http->read_chunk();
2 if (is_array($chunk)) {
3 $chunk_found = true;
4 echo "Chunk size: ",$chunk[1];
5 echo "Chunk data: ",$chunk[0];
6 } else {
7 $found_chunk = false;
8 $content = $chunk.$http->read(1024);
9 }
Read headers.
Headers will be returned in an array:
[0] => (0 => 'Host', 1 => 'host.com') [1] => (0 => 'Connection', 1 => 'close') ...Because there can be multiple headers with the same name, we don't put it into an associative array, if we did the previous header of the same name would be overwritten.
Read line
Like builtin fgets(): Returns a string of up to length - 1 bytes. Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, the length defaults to 1k, or 1024 bytes.
Read status line
This method will ignore empty lines (lines with no content, or just white space), and will assume the first non-empty line encountered is the status line. If status line is matched, an array will be returned with the following keys: (0 => HTTP-Version, 1 => Status-Code, 2 => Reason-Phrase) If status line is not found, the first non-empty line encountered will be returned.
Set read/write timeout
seconds
microseconds (default: 0)
Write
Like builtin fwrite(): writes the contents of string. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.
(optional)
Documention generated on Wed, 16 Jul 2003 01:03:17 +0100 by phpDocumentor 1.2.0