Class CakeSocket
CakePHP network socket connection class.
Core base class for network communication.
Direct Subclasses
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Network/CakeSocket.php
Properties summary
-
$_baseConfig
protectedarray
Base configuration settings for the socket connection -
$_connectionErrors
protectedarray
Used to capture connection warnings which can happen when there are SSL errors for example.
-
$_encryptMethods
protectedarray
Contains all the encryption methods available -
$config
publicarray
Configuration settings for the socket connection -
$connected
publicboolean
This boolean contains the current state of the CakeSocket class -
$connection
publicresource
Reference to socket connection resource -
$description
publicstring
Object description -
$encrypted
publicboolean
True if the socket stream is encrypted after a CakeSocket::enableCrypto() call -
$lastError
publicarray
This variable contains an array with the last error number (num) and string (str)
Method Summary
-
__construct() public
Constructor. -
__destruct() public
Destructor, used to disconnect from current connection. -
_connectionErrorHandler() protected
socket_stream_client() does not populate errNum, or $errStr when there are connection errors, as in the case of SSL verification failure.
-
address() public
Get the IP address of the current connection. -
addresses() public
Get all IP addresses associated with the current connection. -
connect() public
Connect the socket to the given host and port. -
context() public
Get the connection context. -
disconnect() public
Disconnect the socket from the current connection. -
enableCrypto() public
Encrypts current stream socket, using one of the defined encryption methods -
host() public
Get the host name of the current connection. -
lastError() public
Get the last error as a string. -
read() public
Read data from the socket. Returns false if no data is available or no connection could be established.
-
reset() public
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed) -
setLastError() public
Set the last error. -
write() public
Write data to the socket.
Method Detail
__construct() public ¶
__construct( array $config = array() )
Constructor.
Parameters
- array $config optional array()
- Socket configuration, which will be merged with the base configuration
See
_connectionErrorHandler() protected ¶
_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.
Parameters
- integer $code
- string $message
address() public ¶
address( )
Get the IP address of the current connection.
Returns
IP address
addresses() public ¶
addresses( )
Get all IP addresses associated with the current connection.
Returns
IP addresses
context() public ¶
context( )
Get the connection context.
Returns
Null when there is no connection, an array when there is.
disconnect() public ¶
disconnect( )
Disconnect the socket from the current connection.
Returns
Success
enableCrypto() public ¶
enableCrypto( string $type , string $clientOrServer = 'client' , boolean $enable = true )
Encrypts current stream socket, using one of the defined encryption methods
Parameters
- string $type
- can be one of 'ssl2', 'ssl3', 'ssl23' or 'tls'
- string $clientOrServer optional 'client'
- can be one of 'client', 'server'. Default is 'client'
- boolean $enable optional true
- enable or disable encryption. Default is true (enable)
Returns
True on success
Throws
When an invalid encryption scheme is chosen.
SocketException
When attempting to enable SSL/TLS fails
See
read() public ¶
read( integer $length = 1024 )
Read data from the socket. Returns false if no data is available or no connection could be established.
Parameters
- integer $length optional 1024
- Optional buffer length to read; defaults to 1024
Returns
Socket data
reset() public ¶
reset( array $state = null )
Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
Parameters
- array $state optional null
- Array with key and values to reset
Returns
True on success
setLastError() public ¶
setLastError( integer $errNum , string $errStr )
Set the last error.
Parameters
- integer $errNum
- Error code
- string $errStr
- Error string
Properties detail
$_baseConfig ¶
Base configuration settings for the socket connection
array( 'persistent' => false, 'host' => 'localhost', 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30 )
$_connectionErrors ¶
Used to capture connection warnings which can happen when there are SSL errors for example.
array()
$_encryptMethods ¶
Contains all the encryption methods available
array( // @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 )
$encrypted ¶
True if the socket stream is encrypted after a CakeSocket::enableCrypto() call
false
$lastError ¶
This variable contains an array with the last error number (num) and string (str)
array()