Instantly share code, notes, and snippets.

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