Last active
March 8, 2023 23:09
-
-
Save tzmfreedom/15599744939388adc880 to your computer and use it in GitHub Desktop.
postgresql notify/listen sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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