UnlimitedSocketPool
in package
implements
SocketPool
uses
ForbidCloning, ForbidSerialization
SocketPool implementation that doesn't impose any limits on concurrent open connections.
Tags
Table of Contents
Interfaces
- SocketPool
- Allows pooling of connections for stateless protocols.
Constants
- ALLOWED_SCHEMES = ['tcp' => null, 'unix' => null]
Properties
- $connector : SocketConnector|null
- $idleTimeout : float
- $objectIdCacheKeyMap : array<int, string>
- $pendingCount : array<string|int, int>
- $sockets : array<string, array<int, SocketEntry>>
Methods
- __construct() : mixed
- __serialize() : never
- __unserialize() : never
- 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.
- __clone() : mixed
- checkoutNewSocket() : Socket
- clearFromId() : void
- normalizeUri() : array<string|int, mixed>
Constants
ALLOWED_SCHEMES
private
mixed
ALLOWED_SCHEMES
= ['tcp' => null, 'unix' => null]
Properties
$connector read-only
private
SocketConnector|null
$connector
= null
$idleTimeout read-only
private
float
$idleTimeout
= 10
$objectIdCacheKeyMap
private
array<int, string>
$objectIdCacheKeyMap
= []
$pendingCount
private
array<string|int, int>
$pendingCount
= []
$sockets
private
array<string, array<int, SocketEntry>>
$sockets
= []
Methods
__construct()
public
__construct([float $idleTimeout = 10 ][, SocketConnector|null $connector = null ]) : mixed
Parameters
- $idleTimeout : float = 10
- $connector : SocketConnector|null = null
__serialize()
public
final __serialize() : never
Return values
never__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
nevercheckin()
Return a previously checked-out socket to the pool, so it can be reused.
public
checkin(Socket $socket) : void
Parameters
- $socket : Socket
-
Socket instance.
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.
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.
__clone()
protected
final __clone() : mixed
checkoutNewSocket()
private
checkoutNewSocket(string $uri, string $cacheKey[, ConnectContext|null $connectContext = null ][, Cancellation|null $cancellation = null ]) : Socket
Parameters
- $uri : string
- $cacheKey : string
- $connectContext : ConnectContext|null = null
- $cancellation : Cancellation|null = null
Return values
SocketclearFromId()
private
clearFromId(Socket $socket) : void
Parameters
- $socket : Socket
normalizeUri()
private
normalizeUri(string $uri) : array<string|int, mixed>
Parameters
- $uri : string