Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom
Last active March 8, 2023 23:09
Show Gist options
  • Save tzmfreedom/15599744939388adc880 to your computer and use it in GitHub Desktop.
Save tzmfreedom/15599744939388adc880 to your computer and use it in GitHub Desktop.
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