大网数据广告活动
PHP 语言与运行手册

Stomp::__construct · 打开连接

· 52CE 我爱测

注意: A transaction header may be specified, indicating that the message acknowledgment should be part of the named transaction.

Stomp::__construct

stomp_connect

(PECL stomp >= 0.1.0)

Stomp::__construct -- stomp_connect — 打开连接

说明

面向对象风格 (constructor):

public function Stomp::__construct(
    string $broker = ini_get("stomp.default_broker_uri"),
    string $username = ?,
    string $password = ?,
    array $headers = ?
)

过程化风格:

function stomp_connect(
    string $broker = ini_get("stomp.default_broker_uri"),
    string $username = ?,
    string $password = ?,
    array $headers = ?
): resource

打开兼容 stomp 通讯协议的消息代理服务器的连接。

参数

broker

代理 URI

username

用户名。

password

密码。

headers

关联数组包含附加的头信息(例如: receipt)。

返回值

注意:

A transaction header may be specified, indicating that the message acknowledgment should be part of the named transaction.

更新日志

版本 说明
PECL stomp 1.0.1 增加 headers 参数

示例

示例 #1 面向对象风格

<?php

/* 连接 */
try {
    $stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
    die('Connection failed: ' . $e->getMessage());
}

/* close connection */
unset($stomp);

?>

示例 #2 过程化风格

<?php

/* 连接 */
$link = stomp_connect('ssl://localhost:61612');

/* 检查链接 */
if (!$link) {
    die('Connection failed: ' . stomp_connect_error());
}

/* 关闭连接 */
stomp_close($link);

?>

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。