Class Socket

Summary

Fully Qualified Name: Laminas\Http\Client\Adapter\Socket
Implements: AdapterInterface, StreamInterface

Description

A sockets based (stream\socket\client) adapter class for Laminas\Http\Client. Can be used on almost every PHP environment, and does not require any special extensions.

Methods

Name Description Defined By
__construct() Adapter constructor, currently empty. Config is set using setOptions() Socket
__destruct() Destructor: make sure the socket is disconnected Socket
close() Close the connection to the server Socket
connect() Connect to the remote server Socket
getConfig() Retrieve the array of all configuration options Socket
getStreamContext() Get the stream context for the TCP connection to the server. Socket
read() Read response from server Socket
setOptions() Set the configuration array for the adapter Socket
setOutputStream() Set output stream for the response Socket
setStreamContext() Set the stream context for the TCP connection to the server Socket
write() Send request to the remote server Socket

Method Details

__construct()

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

Returns:

__destruct()

Destructor: make sure the socket is disconnected

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

Returns:

close()

Close the connection to the server

Returns:

connect()

Connect to the remote server

Parameter Name Type Description
$host string
$port int
$secure bool

Returns:

getConfig()

Retrieve the array of all configuration options

Returns: array

getStreamContext()

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

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

Returns: resource

read()

Read response from server

Returns: string

setOptions()

Set the configuration array for the adapter

Parameter Name Type Description
$options array|\Traversable

Returns:

setOutputStream()

Set output stream for the response

Parameter Name Type Description
$stream resource

Returns: \Laminas\Http\Client\Adapter\Socket

setStreamContext()

Set the stream context for the TCP connection to the server

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.

Parameter Name Type Description
$context mixed Stream

Returns: $this

write()

Send request to the remote server

Parameter Name Type Description
$method string
$uri \Laminas\Uri\Uri
$httpVer string
$headers array
$body string

Returns: string Request as string

Top