PHP 8.5.2 Released!

Pdo\Pgsql::getNotify

(PHP 8 >= 8.4.0)

Pdo\Pgsql::getNotifyDevuelve una notificación asíncrona

Descripción

public Pdo\Pgsql::getNotify(int $fetchMode = PDO::FETCH_DEFAULT, int $timeoutMilliseconds = 0): array|false

Devuelve un conjunto de resultados que representa una notificación asíncrona pendiente.

Parámetros

fetchMode

El formato en el que debe estar el conjunto de resultados, una de las constantes siguientes:

timeoutMilliseconds
El tiempo de espera para una respuesta, en milisegundos.

Valores devueltos

Si una o varias notificaciones están pendientes, devuelve una sola fila, con los campos message y pid, en caso contrario devuelve false.

Errores/Excepciones

Se lanza una ValueError si fetchMode no es una de las constantes PDO::FETCH_* válidas.

Se lanza una ValueError si timeoutMilliseconds es inferior a 0.

Se lanza una Warning si timeoutMilliseconds es superior al valor que puede contener un entero firmado de 32 bits, en cuyo caso será el valor máximo de un entero firmado de 32 bits.

Ver también

add a note

User Contributed Notes 1 note

up
0
sage at sage dot sk
8 days ago
This page needs an example to understand that you **need** to explicitly call LISTEN before using getNotify, like shown in https://www.php.net/manual/en/function.pg-get-notify.php

<?php

$db = new PDO($dsn, $user, $password, $options);
$db->query('LISTEN test');
$notification = $db->pgsqlGetNotify(PDO::FETCH_ASSOC, 10000);

// or

$db = new Pdo\Pgsql($dsn, $user, $password, $options);
$db->query('LISTEN test');
$notification = $db->getNotify(PDO::FETCH_ASSOC, 10000);

// now you can call NOTIFY elsewhere
// PG> NOTIFY test, 'payload string';
var_dump($notification);

?>

array(3) {
  ["message"]=>
  string(4) "test"
  ["pid"]=>
  int(123565)
  ["payload"]=>
  string(14) "payload string"
}

If you called NOTIFY before calling LISTEN, nothing will be returned!

You receive the first notification only, and you have to call getNotify again. And call LISTEN again if DB connection drops.
To Top