CakePHP network socket connection class.
Core base class for network communication.
$_connectionErrors
protected array
Used to capture connection warnings which can happen when there are SSL errors for example.
$_defaultConfig
protected array
$_encryptMethods
protected array
$connected
public boolean
$connection
public resource|null
$description
public string
$encrypted
public boolean
$lastError
public array
socket_stream_client() does not populate errNum, or $errStr when there are connection errors, as in the case of SSL verification failure.
Read data from the socket. Returns false if no data is available or no connection could be established.
__construct( array $config [] )
Constructor.
$config
optional [] _connectionErrorHandler( integer $code , string $message )
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.
$code
$message
_setSslContext( string $host )
Configure the SSL context options.
$host
address( )
Get the IP address of the current connection.
addresses( )
Get all IP addresses associated with the current connection.
connect( )
Connect the socket to the given host and port.
Cake\Network\Exception\SocketException
context( )
Get the connection context.
disconnect( )
Disconnect the socket from the current connection.
enableCrypto( string $type , string $clientOrServer 'client' , boolean $enable true )
Encrypts current stream socket, using one of the defined encryption methods
$type
$clientOrServer
optional 'client' $enable
optional true Cake\Network\Exception\SocketException
read( integer $length 1024 )
Read data from the socket. Returns false if no data is available or no connection could be established.
$length
optional 1024 reset( array|null $state null )
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
$state
optional null setLastError( integer $errNum , string $errStr )
Set the last error.
$errNum
$errStr
write( string $data )
Write data to the socket.
$data
_configDelete( string $key )
Deletes a single config key.
$key
Cake\Core\Exception\Exception
_configRead( string|null $key )
Reads a config key.
$key
_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Writes a config key.
$key
$value
$merge
optional false True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Cake\Core\Exception\Exception
config( string|array|null $key null , mixed|null $value null , boolean $merge true )
Gets/Sets the config.
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key');
Reading a nested value:
$this->config('some.nested.key');
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
optional null $value
optional null $merge
optional true Cake\Core\Exception\Exception
configShallow( string|array $key , mixed|null $value null )
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->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
$value
optional null getConfig( string|null $key null )
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');
$key
optional null setConfig( string|array $key , mixed|null $value null , boolean $merge true )
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']);
$key
$value
optional null $merge
optional true Cake\Core\Exception\Exception
protected array
Used to capture connection warnings which can happen when there are SSL errors for example.
[]
protected array
Default configuration settings for the socket connection
[ 'persistent' => false, 'host' => 'localhost', 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30 ]
protected array
Contains all the encryption methods available
[ // @codingStandardsIgnoreStart 'sslv2_client' => STREAM_CRYPTO_METHOD_SSLv2_CLIENT, 'sslv3_client' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT, 'sslv23_client' => STREAM_CRYPTO_METHOD_SSLv23_CLIENT, 'tls_client' => STREAM_CRYPTO_METHOD_TLS_CLIENT, 'sslv2_server' => STREAM_CRYPTO_METHOD_SSLv2_SERVER, 'sslv3_server' => STREAM_CRYPTO_METHOD_SSLv3_SERVER, 'sslv23_server' => STREAM_CRYPTO_METHOD_SSLv23_SERVER, 'tls_server' => STREAM_CRYPTO_METHOD_TLS_SERVER // @codingStandardsIgnoreEnd ]
public boolean
True if the socket stream is encrypted after a Cake\Network\Socket::enableCrypto() call
false
public array
This variable contains an array with the last error number (num) and string (str)
[]
© 2005–2017 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/3.4/class-Cake.Network.Socket.html