Documentation

SocketPool
in

Allows pooling of connections for stateless protocols.

Table of Contents

Methods

checkin()  : void
Return a previously checked-out socket to the pool, so it can be reused.
checkout()  : Socket
Checkout a socket from the specified URI authority.
clear()  : void
Remove the specified socket from the pool.

Methods

checkin()

Return a previously checked-out socket to the pool, so it can be reused.

public checkin(Socket $socket) : void
Parameters
$socket : Socket

Socket instance.

Tags
throws
Error

If the provided resource is unknown to the pool.

checkout()

Checkout a socket from the specified URI authority.

public checkout(string $uri[, ConnectContext|null $context = null ][, Cancellation|null $cancellation = null ]) : Socket

The resulting socket resource should be checked back in via SocketPool::checkin() once the calling code is finished with the stream (even if the socket has been closed). Failure to checkin sockets will result in memory leaks and socket queue blockage. Instead of checking the socket in again, it can also be cleared to prevent re-use.

Parameters
$uri : string

URI in scheme://host:port format. TCP is assumed if no scheme is present. An optional fragment component can be used to differentiate different socket groups connected to the same URI. Connections to the same host with a different ConnectContext must use separate socket groups internally to prevent TLS negotiation with the wrong peer name or other TLS settings.

$context : ConnectContext|null = null

Socket connect context to use when connecting.

$cancellation : Cancellation|null = null

Optional cancellation token to cancel the checkout request.

Tags
throws
SocketException
throws
CancelledException
Return values
Socket

Resolves to an Socket instance once a connection is available.

clear()

Remove the specified socket from the pool.

public clear(Socket $socket) : void
Parameters
$socket : Socket

Socket instance.

Tags
throws
Error

If the provided resource is unknown to the pool.


        
On this page

Search results