CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Socket

Class Socket

CakePHP network socket connection class.

Core base class for network communication.

Cake\Network\Socket uses Cake\Core\InstanceConfigTrait
Namespace: Cake\Network
Location: Network/Socket.php

Properties summary

  • $_connectionErrors protected
    array

    Used to capture connection warnings which can happen when there are SSL errors for example.

  • $_defaultConfig protected
    array
    Default configuration settings for the socket connection
  • $_encryptMethods protected
    array
    Contains all the encryption methods available
  • $connected public
    boolean
    This boolean contains the current state of the Socket class
  • $connection public
    resource|null
    Reference to socket connection resource
  • $description public
    string
    Object description
  • $encrypted public
    boolean
    True if the socket stream is encrypted after a Cake\Network\Socket::enableCrypto() call
  • $lastError public
    array
    This variable contains an array with the last error number (num) and string (str)

Inherited Properties

  • _config, _configInitialized

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.

  • _setSslContext() protected
    Configure the SSL context options.
  • 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 [] )

Constructor.

Parameters
array $config optional []
Socket configuration, which will be merged with the base configuration
See
\Cake\Network\Socket::$_baseConfig

__destruct() public ¶

__destruct( )

Destructor, used to disconnect from current connection.

_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
Code number.
string $message
Message.

_setSslContext() protected ¶

_setSslContext( string $host )

Configure the SSL context options.

Parameters
string $host
The host name being connected to.

address() public ¶

address( )

Get the IP address of the current connection.

Returns
string
IP address

addresses() public ¶

addresses( )

Get all IP addresses associated with the current connection.

Returns
array
IP addresses

connect() public ¶

connect( )

Connect the socket to the given host and port.

Returns
boolean
Success
Throws
Cake\Network\Exception\SocketException

context() public ¶

context( )

Get the connection context.

Returns
null|array
Null when there is no connection, an array when there is.

disconnect() public ¶

disconnect( )

Disconnect the socket from the current connection.

Returns
boolean
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
boolean
True on success
Throws
InvalidArgumentException
When an invalid encryption scheme is chosen.
Cake\Network\Exception\SocketException
When attempting to enable SSL/TLS fails
See
stream_socket_enable_crypto

host() public ¶

host( )

Get the host name of the current connection.

Returns
string
Host name

lastError() public ¶

lastError( )

Get the last error as a string.

Returns
string|null
Last error

read() public ¶

read( integer $length 1024 )

Read data from the socket. Returns false if no data is available or no connection could be established.

The bool false return value is deprecated and will be null in the next major. Please code respectively to be future proof.

Parameters
integer $length optional 1024
Optional buffer length to read; defaults to 1024
Returns
mixed
Socket data

reset() public ¶

reset( array|null $state null )

Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)

Parameters
array|null $state optional null
Array with key and values to reset
Returns
boolean
True on success

setLastError() public ¶

setLastError( integer $errNum , string $errStr )

Set the last error.

Parameters
integer $errNum
Error code
string $errStr
Error string

write() public ¶

write( string $data )

Write data to the socket.

The bool false return value is deprecated and will be int 0 in the next major. Please code respectively to be future proof.

Parameters
string $data
The data to write to the socket.
Returns
integer|false
Bytes written.

Methods used from Cake\Core\InstanceConfigTrait

_configDelete() protected ¶

_configDelete( string $key )

Deletes a single config key.

Parameters
string $key
Key to delete.
Throws
Cake\Core\Exception\Exception
if attempting to clobber existing config

_configRead() protected ¶

_configRead( string|null $key )

Reads a config key.

Parameters
string|null $key
Key to read.
Returns
mixed

_configWrite() protected ¶

_configWrite( string|array $key , mixed $value , boolean|string $merge false )

Writes a config key.

Parameters
string|array $key
Key to write to.
mixed $value
Value to write.
boolean|string $merge optional false

True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Throws
Cake\Core\Exception\Exception
if attempting to clobber existing config

config() public ¶

config( string|array|null $key null , mixed|null $value null , boolean $merge true )

Gets/Sets the config.

Usage

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']);
Deprecated
3.4.0 use setConfig()/getConfig() instead.
Parameters
string|array|null $key optional null
The key to get/set, or a complete array of configs.
mixed|null $value optional null
The value to set.
boolean $merge optional true
Whether to recursively merge or overwrite existing config, defaults to true.
Returns
mixed
Config value being read, or the object itself on write operations.
Throws
Cake\Core\Exception\Exception
When trying to set a key that is invalid.

configShallow() public ¶

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->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']);
Parameters
string|array $key
The key to set, or a complete array of configs.
mixed|null $value optional null
The value to set.
Returns

$this

getConfig() public ¶

getConfig( string|null $key null , mixed $default null )

Returns the config.

Usage

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');
Parameters
string|null $key optional null
The key to get or null for the whole config.
mixed $default optional null
The return value when the key does not exist.
Returns
mixed
Config value being read.

setConfig() public ¶

setConfig( string|array $key , mixed|null $value null , boolean $merge true )

Sets the config.

Usage

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']);
Parameters
string|array $key
The key to set, or a complete array of configs.
mixed|null $value optional null
The value to set.
boolean $merge optional true
Whether to recursively merge or overwrite existing config, defaults to true.
Returns

$this
Throws
Cake\Core\Exception\Exception
When trying to set a key that is invalid.

Properties detail

$_connectionErrors ¶

protected array

Used to capture connection warnings which can happen when there are SSL errors for example.

[]

$_defaultConfig ¶

protected array

Default configuration settings for the socket connection

[
    'persistent' => false,
    'host' => 'localhost',
    'protocol' => 'tcp',
    'port' => 80,
    'timeout' => 30
]

$_encryptMethods ¶

protected array

Contains all the encryption methods available

SSLv2 and SSLv3 are deprecated, and should not be used as they have several published vulnerablilities.

[
    // @codingStandardsIgnoreStart
    // @deprecated Will be removed in 4.0.0
    'sslv2_client' => STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
    // @deprecated Will be removed in 4.0.0
    'sslv3_client' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
    'sslv23_client' => STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
    'tls_client' => STREAM_CRYPTO_METHOD_TLS_CLIENT,
    'tlsv10_client' => STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT,
    'tlsv11_client' => STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT,
    'tlsv12_client' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
    // @deprecated Will be removed in 4.0.0
    'sslv2_server' => STREAM_CRYPTO_METHOD_SSLv2_SERVER,
    // @deprecated Will be removed in 4.0.0
    'sslv3_server' => STREAM_CRYPTO_METHOD_SSLv3_SERVER,
    'sslv23_server' => STREAM_CRYPTO_METHOD_SSLv23_SERVER,
    'tls_server' => STREAM_CRYPTO_METHOD_TLS_SERVER,
    'tlsv10_server' => STREAM_CRYPTO_METHOD_TLSv1_0_SERVER,
    'tlsv11_server' => STREAM_CRYPTO_METHOD_TLSv1_1_SERVER,
    'tlsv12_server' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
    // @codingStandardsIgnoreEnd
]

$connected ¶

public boolean

This boolean contains the current state of the Socket class

false

$connection ¶

public resource|null

Reference to socket connection resource

$description ¶

public string

Object description

'Remote DataSource Network Socket Interface'

$encrypted ¶

public boolean

True if the socket stream is encrypted after a Cake\Network\Socket::enableCrypto() call

false

$lastError ¶

public array

This variable contains an array with the last error number (num) and string (str)

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs