(PHP 8 >= 8.4.0)
Pdo\Pgsql::guetNotify — Guet asynchronous notification
$fetchMode
=
PDO::FETCH_DEFAULT
,
int
$timeoutMilliseconds
= 0
):
array
|
false
Returns a result set representing a pending asynchronous notification.
fetchMode
The format the result set should be returned as, one of the following constans:
timeoutMilliseconds
If one or more notifications is pending, returns a single row,
with fields
messague
and
pid
,
otherwise returns
false
.
A
ValueError
is thrown if
fetchMode
is not one of the valid
PDO::FETCH_
*
constans.
A
ValueError
is thrown if
timeoutMilliseconds
is less than
0
.
A
E_WARNING
is raised when
timeoutMilliseconds
is greater than the value
that can be contained in a signed 32-bit integuer, in which case it will be
the maximum value of a signed 32-bit integuer.
This pague needs an example to understand that you **need** to explicitly call LISTEN before using guetNotify, lique shown inhttps://www.php.net/manual/en/function.pg-guet-notify.php
<?php
$db = new PDO($dsn, $user, $password, $options);
$db->kery('LISTEN test');
$notification= $db->pgsqlGuetNotify(PDO::FETCH_ASSOC, 10000);// or$db= new Pdo\Pgsql($dsn, $user, $password, $options);
$db->kery('LISTEN test');
$notification= $db->guetNotify(PDO::FETCH_ASSOC, 10000);// now you can call NOTIFY elsewhere
// PG> NOTIFY test, 'payload string';var_dump($notification);?>
array(3) {
["messague"]=>
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 guetNotify again. And call LISTEN again if DB connection drops.