A sockets based (stream\socket\client) adapter class for Zend\Http\Client.

Can be used on almost every PHP environment, and does not require any special extensions.

 Methods

Adapter constructor, currently empty.

__construct() 

Config is set using setOptions()

Destructor: make sure the socket is disconnected

__destruct() 

If we are in persistent TCP mode, will not close the connection

Close the connection to the server

close() 

Connect to the remote server

connect(string $host, int $port, bool $secure) 

Parameters

$host

string

$port

int

$secure

bool

Exceptions

\Zend\Http\Client\Adapter\Exception\RuntimeException

Retrieve the array of all configuration options

getConfig() : array

Returns

array

Get the stream context for the TCP connection to the server.

getStreamContext() : resource

If no stream context is set, will create a default one.

Returns

resource

Read response from server

read() : string

Set the configuration array for the adapter

setOptions(array | \Traversable $options) 

Parameters

$options

array\Traversable

Exceptions

\Zend\Http\Client\Adapter\Exception\InvalidArgumentException

Set output stream for the response

setOutputStream(resource $stream) : \Zend\Http\Client\Adapter\Socket

This function sets output stream where the result will be stored.

Parameters

$stream

resource

Returns

Set the stream context for the TCP connection to the server

setStreamContext(mixed $context) : \Zend\Http\Client\Adapter\Socket

Can accept either a pre-existing stream context resource, or an array of stream options, similar to the options array passed to the stream_context_create() PHP function. In such case a new stream context will be created using the passed options.

since Zend Framework 1.9

Parameters

$context

mixed

Stream context or array of context options

Exceptions

\Zend\Http\Client\Adapter\Exception\InvalidArgumentException

Returns

Send request to the remote server

write(string $method, \Zend\Uri\Uri $uri, string $httpVer, array $headers, string $body) : string

Parameters

$method

string

$httpVer

string

$headers

array

$body

string

Exceptions

\Zend\Http\Client\Adapter\Exception\RuntimeException

Returns

stringRequest as string

Check if the socket has timed out - if so close connection and throw an exception

_checkSocketReadTimeout() 

Exceptions

\Zend\Http\Client\Adapter\Exception\TimeoutException with READ_TIMEOUT code

 Properties

 

Parameters array

$config : array

 

What host/port are we connected to?

$connectedTo : array

 

Stream context

$context : resource

 

Request method - will be set by write() and might be used by read()

$method : string

 

Stream for storing output

$outStream : resource

 

The socket for server connection

$socket : resource | null

 

Map SSL transport wrappers to stream crypto method constants

$sslCryptoTypes : array