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.

package Default

 Methods

Adapter constructor, currently empty. Config is set using setOptions()

__construct() 

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() 
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::close()

Connect to the remote server

connect(string $host, integer $port = 80, boolean $secure = false
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::connect()

Parameters

$host

string

$port

integer

$secure

boolean

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
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::read()

Exceptions

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

Returns

string

Set the configuration array for the adapter

setOptions(array|\Traversable $options = array()
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::setOptions()

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.

inherited_from \Zend\Http\Client\Adapter\StreamInterface::setOutputStream()

Parameters

$stream

resource

Returns

\Zend\Http\Client\Adapter\Socket

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

\Zend\Http\Client\Adapter\Socket

Send request to the remote server

write(string $method, \Zend\Uri\Uri $uri, string $httpVer = '1.1', array $headers = array(), string $body = '') : string
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::write()

Parameters

$method

string

$uri

\Zend\Uri\Uri

$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

Default

array('persistent' => false, 'ssltransport' => 'ssl', 'sslcert' => null, 'sslpassphrase' => null, 'sslverifypeer' => true, 'sslcafile' => null, 'sslcapath' => null, 'sslallowselfsigned' => false, 'sslusecontext' => false)
 

What host/port are we connected to?

$connectedTo : array

Default

array(null, null)
 

Stream context

$context : resource

Default

null
 

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

$method : string

Default

null
 

Stream for storing output

$outStream : resource

Default

null
 

The socket for server connection

$socket : resource | null

Default

null
 

Map SSL transport wrappers to stream crypto method constants

$sslCryptoTypes : array

Default

array('ssl' => STREAM_CRYPTO_METHOD_SSLv23_CLIENT, 'sslv2' => STREAM_CRYPTO_METHOD_SSLv2_CLIENT, 'sslv3' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT, 'tls' => STREAM_CRYPTO_METHOD_TLS_CLIENT)
Static