Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom tzmfreedom/pg_notify.php
Last active Mar 15, 2018

Embed
What would you like to do?
postgresql notify/listen sample
<?php
$db = new PDO(
"pgsql:dbname=postgres host=localhost port=5432", 'postgres', 'postgres', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
$db->exec('LISTEN hoge');
while ($result = $db->pgsqlGetNotify(PDO::FETCH_ASSOC, 30000)) {
echo json_encode($result) . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.