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

pg_get_notify · 获取 SQL NOTIFY 消息

· 52CE 我爱测

pg_get_notify() 取得 SQL 命令 NOTIFY 生成的消息。要接收通知,必须发送 SQL 命令 LISTEN。

pg_get_notify

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

pg_get_notify — 获取 SQL NOTIFY 消息

说明

function pg_get_notify(PgSql\Connection $connection, int $mode = PGSQL_ASSOC): array|false

pg_get_notify() 取得 SQL 命令 NOTIFY 生成的消息。要接收通知,必须发送 SQL 命令 LISTEN。

参数

connection

PgSql\Connection 实例。

mode

An optional parameter that controls how the returned array is indexed. mode is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM and PGSQL_BOTH. Using PGSQL_NUM, the function will return an array with numerical indices, using PGSQL_ASSOC it will return only associative indices while PGSQL_BOTH will return both numerical and associative indices.

返回值

包含 NOTIFY 消息名称和后端 PID 的 array。如果服务器支持,该数组还包含服务器版本和有效负载。否则,如果没有 NOTIFY 正在等待,则返回 false。

更新日志

版本 说明
8.1.0 现在 connection 参数接受 PgSql\Connection 实例,之前接受 resource。

示例

示例 #1 PostgreSQL NOTIFY 消息

<?php 
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
  echo "An error occurred.\n";
  exit;
}

// 从其它进程监听 'author_updated' 消息
pg_query($conn, 'LISTEN author_updated;');
$notify = pg_get_notify($conn);
if (!$notify) {
  echo "No messages\n";
} else {
  print_r($notify);
}
?>

参见

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

资料来源与适用范围

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

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

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