CakePHP network socket connection class.
Core base class for network communication.
array<string, mixed>Runtime config
boolWhether the config property has already been configured with defaults
array<string>Used to capture connection warnings which can happen when there are SSL errors for example.
array<string, mixed>Default configuration settings for the socket connection
array<string, int>Contains all the encryption methods available
boolThis boolean contains the current state of the Socket class
resource|nullReference to socket connection resource
boolTrue if the socket stream is encrypted after a {@link \Cake\Network\Socket::enableCrypto()} call
array<string, mixed>This variable contains an array with the last error number (num) and string (str)
Constructor.
Destructor, used to disconnect from current connection.
Temporary magic method to allow accessing protected properties.
Deletes a single config key.
Reads a config key.
Writes a config key.
socket_stream_client() does not populate errNum, or $errStr when there are connection errors, as in the case of SSL verification failure.
Create a stream socket client. Mock utility.
Configure the SSL context options.
Get the IP address of the current connection.
Get all IP addresses associated with the current connection.
Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.
Connect the socket to the given host and port.
Get the connection context.
Disconnect the socket from the current connection.
Encrypts current stream socket, using one of the defined encryption methods
Returns the config.
Returns the config for this specific key.
Get the host name of the current connection.
Check the connection status after calling connect().
Check the encryption status after calling enableCrypto().
Get the last error as a string.
Read data from the socket. Returns null if no data is available or no connection could be established.
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
Sets the config.
Set the last error.
Write data to the socket.
__construct(array<string, mixed> $config = [])
Constructor.
array<string, mixed> $config optional Socket configuration, which will be merged with the base configuration
__destruct()
Destructor, used to disconnect from current connection.
__get(string $name): mixed
Temporary magic method to allow accessing protected properties.
Will be removed in 5.0.
string $name Property name.
mixed_configDelete(string $key): void
Deletes a single config key.
string $key Key to delete.
voidCake\Core\Exception\CakeException_configRead(string|null $key): mixed
Reads a config key.
string|null $key Key to read.
mixed_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void
Writes a config key.
array<string, mixed>|string $key Key to write to.
mixed $value Value to write.
string|bool $merge optional True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
voidCake\Core\Exception\CakeException_connectionErrorHandler(int $code, string $message): void
socket_stream_client() does not populate errNum, or $errStr when there are connection errors, as in the case of SSL verification failure.
Instead we need to handle those errors manually.
int $code Code number.
string $message Message.
void_getStreamSocketClient(string $remoteSocketTarget, int $errNum, string $errStr, int $timeout, int $connectAs, resource $context): resource|null
Create a stream socket client. Mock utility.
string $remoteSocketTarget remote socket
int $errNum error number
string $errStr error string
int $timeout timeout
int $connectAs flags
resource $context context
resource|null_setSslContext(string $host): void
Configure the SSL context options.
string $host The host name being connected to.
voidaddress(): string
Get the IP address of the current connection.
stringaddresses(): array
Get all IP addresses associated with the current connection.
arrayconfigShallow(array<string, mixed>|string $key, mixed|null $value = null): $this
Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->configShallow('key', $value); Setting a nested value:
$this->configShallow('some.nested.key', $value); Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
array<string, mixed>|string $key The key to set, or a complete array of configs.
mixed|null $value optional The value to set.
$thisconnect(): bool
Connect the socket to the given host and port.
boolCake\Network\Exception\SocketExceptioncontext(): array|null
Get the connection context.
array|nulldisconnect(): bool
Disconnect the socket from the current connection.
boolenableCrypto(string $type, string $clientOrServer = 'client', bool $enable = true): void
Encrypts current stream socket, using one of the defined encryption methods
string $type can be one of 'ssl2', 'ssl3', 'ssl23' or 'tls'
string $clientOrServer optional can be one of 'client', 'server'. Default is 'client'
bool $enable optional enable or disable encryption. Default is true (enable)
voidInvalidArgumentExceptionCake\Network\Exception\SocketExceptiongetConfig(string|null $key = null, mixed $default = null): mixed
Returns the config.
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key'); Reading a nested value:
$this->getConfig('some.nested.key'); Reading with default value:
$this->getConfig('some-key', 'default-value'); string|null $key optional The key to get or null for the whole config.
mixed $default optional The return value when the key does not exist.
mixedgetConfigOrFail(string $key): mixed
Returns the config for this specific key.
The config value for this key must exist, it can never be null.
string $key The key to get.
mixedInvalidArgumentExceptionhost(): string
Get the host name of the current connection.
stringisConnected(): bool
Check the connection status after calling connect().
boolisEncrypted(): bool
Check the encryption status after calling enableCrypto().
boollastError(): string|null
Get the last error as a string.
string|nullread(int $length = 1024): string|null
Read data from the socket. Returns null if no data is available or no connection could be established.
int $length optional Optional buffer length to read; defaults to 1024
string|nullreset(array|null $state = null): void
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
array|null $state optional Array with key and values to reset
voidsetConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this
Sets the config.
Setting a specific value:
$this->setConfig('key', $value); Setting a nested value:
$this->setConfig('some.nested.key', $value); Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
array<string, mixed>|string $key The key to set, or a complete array of configs.
mixed|null $value optional The value to set.
bool $merge optional Whether to recursively merge or overwrite existing config, defaults to true.
$thisCake\Core\Exception\CakeExceptionsetLastError(int|null $errNum, string $errStr): void
Set the last error.
int|null $errNum Error code
string $errStr Error string
voidwrite(string $data): int
Write data to the socket.
string $data The data to write to the socket.
intRuntime config
array<string, mixed>Whether the config property has already been configured with defaults
boolUsed to capture connection warnings which can happen when there are SSL errors for example.
array<string>Default configuration settings for the socket connection
array<string, mixed>Contains all the encryption methods available
array<string, int>This boolean contains the current state of the Socket class
boolReference to socket connection resource
resource|nullTrue if the socket stream is encrypted after a {@link \Cake\Network\Socket::enableCrypto()} call
boolThis variable contains an array with the last error number (num) and string (str)
array<string, mixed>
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Network.Socket.html