CakePHP network socket connection class.
Core base class for network communication.
array<string, mixed>
Runtime config
bool
Whether 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
bool
This boolean contains the current state of the Socket class
resource|null
Reference to socket connection resource
bool
True 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.
void
Cake\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.
void
Cake\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.
void
address(): string
Get the IP address of the current connection.
string
addresses(): array
Get all IP addresses associated with the current connection.
array
configShallow(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.
$this
connect(): bool
Connect the socket to the given host and port.
bool
Cake\Network\Exception\SocketException
context(): array|null
Get the connection context.
array|null
disconnect(): bool
Disconnect the socket from the current connection.
bool
enableCrypto(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)
void
InvalidArgumentException
Cake\Network\Exception\SocketException
getConfig(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.
mixed
getConfigOrFail(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.
mixed
InvalidArgumentException
host(): string
Get the host name of the current connection.
string
isConnected(): bool
Check the connection status after calling connect()
.
bool
isEncrypted(): bool
Check the encryption status after calling enableCrypto()
.
bool
lastError(): string|null
Get the last error as a string.
string|null
read(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|null
reset(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
void
setConfig(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.
$this
Cake\Core\Exception\CakeException
setLastError(int|null $errNum, string $errStr): void
Set the last error.
int|null
$errNum Error code
string
$errStr Error string
void
write(string $data): int
Write data to the socket.
string
$data The data to write to the socket.
int
Runtime config
array<string, mixed>
Whether the config property has already been configured with defaults
bool
Used 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
bool
Reference to socket connection resource
resource|null
True if the socket stream is encrypted after a {@link \Cake\Network\Socket::enableCrypto()} call
bool
This 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