Class CakeSocket
CakePHP network socket connection class.
Core base class for network communication.
Direct known subclasses
HttpSocketCopyright: Copyright (c) Cake Software Foundation, Inc. ( http://cakefoundation.org)
License: MIT License
Located at Cake/Network/CakeSocket.php
Method Detail
__constructsource public
__construct( array $config array() )
Constructor.
Parameters
-
array
$config
optional array() - Socket configuration, which will be merged with the base configuration
See
CakeSocket::$_baseConfig
_connectionErrorHandlersource 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
- Code.
-
string
$message
- Message.
_setSslContextsource protected
_setSslContext( string $host )
Configure the SSL context options.
Parameters
-
string
$host
- The host name being connected to.
addresssource public
address( )
Gets the IP address of the current connection.
Returns
string
IP address
addressessource public
addresses( )
Gets all IP addresses associated with the current connection.
Returns
array
IP addresses
connectsource public
connect( )
Connects the socket to the given host and port.
Returns
boolean
Success
Throws
SocketException
SocketException
contextsource public
context( )
Gets the connection context.
Returns
null|array
Null when there is no connection, an array when there is.
disconnectsource public
disconnect( )
Disconnects the socket from the current connection.
Returns
boolean
Success
enableCryptosource public
enableCrypto( string $type , string $clientOrServer 'client' , boolean $enable true )
Encrypts current stream socket, using one of the defined encryption methods.
Parameters
-
string
$type
- Type which can be one of 'sslv2', 'sslv3', 'sslv23' 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
boolean
True on success
Throws
InvalidArgumentException
When an invalid encryption scheme is chosen.
SocketException
When attempting to enable SSL/TLS fails.
See
stream_socket_enable_cryptoreadsource public
read( integer $length 1024 )
Reads 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
mixed
Socket data
resetsource 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
boolean
True on success
setLastErrorsource public
setLastError( integer $errNum , string $errStr )
Sets the last error.
Parameters
-
integer
$errNum
- Error code
-
string
$errStr
- Error string
writesource public
write( string $data )
Writes data to the socket.
Parameters
-
string
$data
- The data to write to the socket
Returns
boolean
Success
Properties summary
$_baseConfigsource
protected array
Base configuration settings for the socket connection
array( 'persistent' => false, 'host' => 'localhost', 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30 )
$_connectionErrorssource
protected array
Used to capture connection warnings which can happen when there are SSL errors for example.
array()
$_encryptMethodssource
protected array
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 )
$connectedsource
public boolean
This boolean contains the current state of the CakeSocket class
false
$encryptedsource
public boolean
True if the socket stream is encrypted after a CakeSocket::enableCrypto() call
false
$lastErrorsource
public array
This variable contains an array with the last error number (num) and string (str)
array()
© 2005–2016 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.
http://api.cakephp.org/2.7/class-CakeSocket.html