CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 业务解决方案
  • 商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • YouTube
    • Facebook
    • 推特
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 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

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
      • Exception
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Socket 类

CakePHP 网络套接字连接类。

网络通信的核心基础类。

命名空间: Cake\Network

属性摘要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    配置属性是否已使用默认值配置

  • $_connectionErrors protected
    list<string>

    用于捕获连接警告,例如 SSL 错误时可能会发生。

  • $_defaultConfig protected
    array<string, mixed>

    套接字连接的默认配置设置

  • $_encryptMethods protected
    array<string, int>

    包含所有可用的加密方法

  • $connected protected
    bool

    此布尔值包含 Socket 类的当前状态

  • $connection protected
    resource|null

    对套接字连接资源的引用

  • $encrypted protected
    bool

    如果套接字流在 {@link \Cake\Network\Socket::enableCrypto()} 调用后被加密,则为 True

  • $lastError protected
    array<string, mixed>

    此变量包含一个数组,其中包含最后一个错误号 (num) 和字符串 (str)

方法摘要

  • __construct() public

    构造函数。

  • __destruct() public

    析构函数,用于断开与当前连接的连接。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _connectionErrorHandler() protected

    socket_stream_client() 不会在出现连接错误时填充 errNum 或 $errStr,例如 SSL 验证失败。

  • _getStreamSocketClient() protected

    创建流套接字客户端。模拟工具。

  • _setSslContext() protected

    配置 SSL 上下文选项。

  • address() public

    获取当前连接的 IP 地址。

  • addresses() public

    获取与当前连接关联的所有 IP 地址。

  • configShallow() public

    将提供的配置与现有配置合并。与 config() 不同,config() 对嵌套键进行递归合并,此方法进行简单合并。

  • connect() public

    将套接字连接到给定的主机和端口。

  • context() public

    获取连接上下文。

  • disconnect() public

    断开套接字与当前连接的连接。

  • enableCrypto() public

    使用定义的加密方法之一加密当前流套接字

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • host() public

    获取当前连接的主机名。

  • isConnected() public

    在调用 connect() 后检查连接状态。

  • isEncrypted() public

    在调用 enableCrypto() 后检查加密状态。

  • lastError() public

    获取最后一个错误作为字符串。

  • read() public

    从套接字读取数据。如果没有可用数据或无法建立连接,则返回 null。

  • reset() public

    将此 Socket 实例的状态重置为其初始状态(在 Object::__construct 执行之前)

  • setConfig() public

    设置配置。

  • setLastError() public

    设置最后一个错误。

  • write() public

    将数据写入套接字。

方法详情

__construct() ¶ public

__construct(array<string, mixed> $config = [])

构造函数。

参数
array<string, mixed> $config optional

套接字配置,它将与基本配置合并

另请参见
\Cake\Network\Socket::$_defaultConfig

__destruct() ¶ public

__destruct()

析构函数,用于断开与当前连接的连接。

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回值
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge optional

如果要递归合并,则为 True,如果要简单合并,则为 'shallow',如果要覆盖,则为 False,默认为 False。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_connectionErrorHandler() ¶ protected

_connectionErrorHandler(int $code, string $message): void

socket_stream_client() 不会在出现连接错误时填充 errNum 或 $errStr,例如 SSL 验证失败。

相反,我们需要手动处理这些错误。

参数
int $code

代码号。

string $message

消息。

返回值
void

_getStreamSocketClient() ¶ protected

_getStreamSocketClient(string $remoteSocketTarget, int $errNum, string $errStr, int $timeout, int $connectAs, resource $context): resource|null

创建流套接字客户端。模拟工具。

参数
string $remoteSocketTarget

远程套接字

int $errNum

错误号

string $errStr

错误字符串

int $timeout

超时

int $connectAs

标志

resource $context

上下文

返回值
resource|null

_setSslContext() ¶ protected

_setSslContext(string $host): void

配置 SSL 上下文选项。

参数
string $host

正在连接到的主机名。

返回值
void

address() ¶ public

address(): string

获取当前连接的 IP 地址。

返回值
string

addresses() ¶ public

addresses(): list<string>

获取与当前连接关联的所有 IP 地址。

返回值
list<string>

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config() 不同,config() 对嵌套键进行递归合并,此方法进行简单合并。

设置特定值

$this->configShallow('key', $value);

设置嵌套值

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value optional

要设置的值。

返回值
$this

connect() ¶ public

connect(): bool

将套接字连接到给定的主机和端口。

返回值
bool
抛出
Cake\Network\Exception\SocketException

context() ¶ public

context(): array<string, mixed>|null

获取连接上下文。

返回值
array<string, mixed>|null

disconnect() ¶ public

disconnect(): bool

断开套接字与当前连接的连接。

返回值
bool

enableCrypto() ¶ public

enableCrypto(string $type, string $clientOrServer = 'client', bool $enable = true): void

使用定义的加密方法之一加密当前流套接字

参数
string $type

可以是 'ssl2'、'ssl3'、'ssl23' 或 'tls' 之一。

string $clientOrServer 可选

可以是 'client'、'server' 之一。默认值为 'client'。

bool $enable 可选

启用或禁用加密。默认值为 true (启用)。

返回值
void
抛出
InvalidArgumentException
当选择无效的加密方案时。
Cake\Network\Exception\SocketException
尝试启用 SSL/TLS 失败时
另请参见
stream_socket_enable_crypto

getConfig() ¶ public

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

返回配置。

用法

读取整个配置

$this->getConfig();

读取特定值

$this->getConfig('key');

读取嵌套值

$this->getConfig('some.nested.key');

使用默认值读取

$this->getConfig('some-key', 'default-value');
参数
string|null $key 可选

要获取的键,如果要获取整个配置,则为 null。

mixed $default 可选

当键不存在时的返回值。

返回值
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,不能为 null。

参数
string $key

要获取的键。

返回值
mixed
抛出
InvalidArgumentException

host() ¶ public

host(): string

获取当前连接的主机名。

返回值
string

isConnected() ¶ public

isConnected(): bool

在调用 connect() 后检查连接状态。

返回值
bool

isEncrypted() ¶ public

isEncrypted(): bool

在调用 enableCrypto() 后检查加密状态。

返回值
bool

lastError() ¶ public

lastError(): string|null

获取最后一个错误作为字符串。

返回值
string|null

read() ¶ public

read(int $length = 1024): string|null

从套接字读取数据。如果没有可用数据或无法建立连接,则返回 null。

参数
int $length 可选

要读取的可选缓冲区长度;默认为 1024。

返回值
string|null

reset() ¶ public

reset(array|null $state = null): void

将此 Socket 实例的状态重置为其初始状态(在 Object::__construct 执行之前)

参数
array|null $state 可选

包含要重置的键值对的数组。

返回值
void

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置特定值

$this->setConfig('key', $value);

设置嵌套值

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value optional

要设置的值。

bool $merge 可选

是否递归合并或覆盖现有配置,默认为 true。

返回值
$this
抛出
Cake\Core\Exception\CakeException
尝试设置无效键时。

setLastError() ¶ public

setLastError(int|null $errNum, string $errStr): void

设置最后一个错误。

参数
int|null $errNum

错误代码

string $errStr

错误字符串

返回值
void

write() ¶ public

write(string $data): int

将数据写入套接字。

参数
string $data

要写入套接字的数据。

返回值
int

属性详细信息

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

配置属性是否已使用默认值配置

类型
bool

$_connectionErrors ¶ protected

用于捕获连接警告,例如 SSL 错误时可能会发生。

类型
list<string>

$_defaultConfig ¶ protected

套接字连接的默认配置设置

类型
array<string, mixed>

$_encryptMethods ¶ protected

包含所有可用的加密方法

类型
array<string, int>

$connected ¶ protected

此布尔值包含 Socket 类的当前状态

类型
bool

$connection ¶ protected

对套接字连接资源的引用

类型
resource|null

$encrypted ¶ protected

如果套接字流在 {@link \Cake\Network\Socket::enableCrypto()} 调用后被加密,则为 True

类型
bool

$lastError ¶ protected

此变量包含一个数组,其中包含最后一个错误号 (num) 和字符串 (str)

类型
array<string, mixed>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • YouTube
  • Facebook
  • 推特
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成