PHP WebSocket2 Library
PHP5 Library for browsing web
HttpSocket Class Reference

Base class for socket ans proxy implementations. More...

Inheritance diagram for HttpSocket:
DumpSocket NetworkSocket WebProxy FileSocket LowLevelSocket HttpProxy SocksProxy Socks4AProxy Socks4Proxy Socks5Proxy

Public Member Functions

 __destruct ()
 Destructor.
 
 sendRequest (WebRequest $request)
 Sends request to socket and returns response. More...
 
 writeRaw ($request)
 Writes raw data to socket. More...
 

Protected Member Functions

 open ($address, $port)
 Opens socket. More...
 
 read ($size)
 Reads raw data from socket. More...
 
 close ()
 Closes socket.
 
 isOpen ()
 Returns true if socket is open. More...
 
 readChunked ($headers, WebRequest $request)
 Reads chunked content from socket and puts chunks to single string. More...
 
 readLength ($length, $headers, WebRequest $request, &$aborted)
 Reads data with specified length from socket. If socket closes connection or no more data is available to reach length, throws WebRequestException. More...
 
 readAll ($headers, WebRequest $request)
 Reads all available data from socket until it closes connection. More...
 
 readUntil ($text)
 Reads all available data from socket until specified substring is found inside contents. More...
 
 readHeaders ()
 Reads response headers. More...
 
 write (WebRequest $request)
 Writes request to socket. More...
 

Detailed Description

Base class for socket ans proxy implementations.

Examples:
response_interception.php.

Member Function Documentation

isOpen ( )
abstractprotected

Returns true if socket is open.

Return values
boolTrue if socket is open
open (   $address,
  $port 
)
abstractprotected

Opens socket.

Parameters
string$addressHostname or IPv4 address
int$portPort
Exceptions
WebRequestExceptionin case of errors
read (   $size)
abstractprotected

Reads raw data from socket.

Parameters
int$sizeSize of data in bytes to read
Return values
stringData that was read from socket
Exceptions
WebRequestExceptionin case of errors
readAll (   $headers,
WebRequest  $request 
)
abstractprotected

Reads all available data from socket until it closes connection.

Parameters
string$headersHTTP response headers
WebRequest$requestOriginal request
Return values
stringRaw response data string (or null when OnReceiveBodyCallback is set and returns false, see NetworkSocket::setOnReceiveBodyCallback)
Exceptions
WebRequestExceptionin case of errors
readChunked (   $headers,
WebRequest  $request 
)
protected

Reads chunked content from socket and puts chunks to single string.

Parameters
string$headersHTTP response headers
WebRequest$requestOriginal request
Return values
stringRaw response data string (or null when OnReceiveBodyCallback is set and returns false, see NetworkSocket::setOnReceiveBodyCallback)
Exceptions
WebRequestExceptionin case of errors
readHeaders ( )
protected

Reads response headers.

Return values
stringRaw response headers string
Exceptions
WebRequestExceptionin case of errors
readLength (   $length,
  $headers,
WebRequest  $request,
$aborted 
)
abstractprotected

Reads data with specified length from socket. If socket closes connection or no more data is available to reach length, throws WebRequestException.

Parameters
int$lengthData length
string$headersHTTP response headers
WebRequest$requestOriginal request
bool_reference$abortedWill be set to true if function was aborted from callback (see NetworkSocket::setOnReceiveBodyCallback)
Return values
stringRaw response data string (or null when OnReceiveBodyCallback is set and returns false, see NetworkSocket::setOnReceiveBodyCallback)
Exceptions
WebRequestExceptionin case of errors
readUntil (   $text)
protected

Reads all available data from socket until specified substring is found inside contents.

Parameters
string$textSubstring to search for
Return values
stringRaw response data string
Exceptions
WebRequestExceptionin case of errors
sendRequest ( WebRequest  $request)
abstract

Sends request to socket and returns response.

Supports HTTP/1.0 and HTTP/1.1 (close and keep-alive connections), chunked contents, gzipped contents.
See also NetworkSocket::setOnReceiveHeadersCallback, NetworkSocket::setOnReceiveBodyCallback.

Return values
WebResponseCallback response
Exceptions
WebRequestExceptionin case of errors
Examples:
response_interception.php.
write ( WebRequest  $request)
protected

Writes request to socket.

Parameters
WebRequest$requestRequest to write
Exceptions
WebRequestExceptionin case of errors
writeRaw (   $request)
abstract

Writes raw data to socket.

Parameters
string$requestRaw data
Exceptions
WebRequestExceptionin case of errors

The documentation for this class was generated from the following file: