HumHub Documentation (unofficial)

Socket
in package
implements AdapterInterface, StreamInterface

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.

Table of Contents

Interfaces

AdapterInterface
An interface description for Laminas\Http\Client\Adapter classes.
StreamInterface
An interface description for Laminas\Http\Client\Adapter\Stream classes.

Properties

$config  : array<string|int, mixed>
Parameters array
$connectedTo  : array<string|int, mixed>
What host/port are we connected to?
$context  : resource
Stream context
$method  : string
Request method - will be set by write() and might be used by read()
$outStream  : resource
Stream for storing output
$setSslCryptoMethod  : bool
$socket  : resource|null
The socket for server connection
$sslCryptoTypes  : array<string|int, mixed>
Map SSL transport wrappers to stream crypto method constants

Methods

__construct()  : mixed
Adapter constructor, currently empty. Config is set using setOptions()
__destruct()  : mixed
Destructor: make sure the socket is disconnected
close()  : mixed
Close the connection to the server
connect()  : mixed
Connect to the remote server
getConfig()  : array<string|int, mixed>
Retrieve the array of all configuration options
getStreamContext()  : resource
Get the stream context for the TCP connection to the server.
read()  : string
Read response from server
setOptions()  : mixed
Set the configuration array for the adapter
setOutputStream()  : Socket
Set output stream for the response
setStreamContext()  : $this
Set the stream context for the TCP connection to the server
write()  : string
Send request to the remote server
_checkSocketReadTimeout()  : mixed
Check if the socket has timed out - if so close connection and throw an exception
enableCryptoTransport()  : mixed

Properties

$config

Parameters array

protected array<string|int, mixed> $config = ['persistent' => false, 'ssltransport' => 'tls', 'sslcert' => null, 'sslpassphrase' => null, 'sslverifypeer' => true, 'sslcafile' => null, 'sslcapath' => null, 'sslallowselfsigned' => false, 'sslusecontext' => false, 'sslverifypeername' => true]

$connectedTo

What host/port are we connected to?

protected array<string|int, mixed> $connectedTo = [null, null]

$context

Stream context

protected resource $context

$method

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

protected string $method

$outStream

Stream for storing output

protected resource $outStream

$setSslCryptoMethod

protected bool $setSslCryptoMethod = true

$socket

The socket for server connection

protected resource|null $socket

$sslCryptoTypes

Map SSL transport wrappers to stream crypto method constants

protected static array<string|int, mixed> $sslCryptoTypes = ['ssl' => \STREAM_CRYPTO_METHOD_SSLv23_CLIENT, 'sslv2' => \STREAM_CRYPTO_METHOD_SSLv2_CLIENT, 'sslv3' => \STREAM_CRYPTO_METHOD_SSLv3_CLIENT, 'tls' => \STREAM_CRYPTO_METHOD_TLS_CLIENT]

Methods

__construct()

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

public __construct() : mixed

__destruct()

Destructor: make sure the socket is disconnected

public __destruct() : mixed

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

close()

Close the connection to the server

public close() : mixed

connect()

Connect to the remote server

public connect(string $host[, int $port = 80 ][, bool $secure = false ]) : mixed
Parameters
$host : string
$port : int = 80
$secure : bool = false
Tags
throws
RuntimeException

getConfig()

Retrieve the array of all configuration options

public getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStreamContext()

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

public getStreamContext() : resource

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

Return values
resource

setOptions()

Set the configuration array for the adapter

public setOptions([array<string|int, mixed>|Traversable $options = [] ]) : mixed
Parameters
$options : array<string|int, mixed>|Traversable = []
Tags
throws
InvalidArgumentException

setOutputStream()

Set output stream for the response

public setOutputStream(resource $stream) : Socket
Parameters
$stream : resource
Return values
Socket

setStreamContext()

Set the stream context for the TCP connection to the server

public setStreamContext(mixed $context) : $this

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.

Parameters
$context : mixed

Stream context or array of context options

Tags
since

Laminas 1.9

throws
InvalidArgumentException
Return values
$this

write()

Send request to the remote server

public write(string $method, Uri $uri[, string $httpVer = '1.1' ][, array<string|int, mixed> $headers = [] ][, string $body = '' ]) : string
Parameters
$method : string
$uri : Uri
$httpVer : string = '1.1'
$headers : array<string|int, mixed> = []
$body : string = ''
Tags
throws
RuntimeException
Return values
string

Request as string

_checkSocketReadTimeout()

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

protected _checkSocketReadTimeout() : mixed
Tags
throws
TimeoutException

with READ_TIMEOUT code

enableCryptoTransport()

protected enableCryptoTransport(string $sslTransport, resource $socket, string $host) : mixed
Parameters
$sslTransport : string

Transport name from $config['ssltransport']

$socket : resource
$host : string

Host name used only for useful exception message


        
On this page

Search results