pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feed[Fwd: How to use LISTEN / NOTIFY in a Perl program]
2+ messages / 2 participants
[nested] [flat]
* [Fwd: How to use LISTEN / NOTIFY in a Perl program]
@ 2005-01-03 08:43 Thierry Missimilly <Thierry.Missimilly@bull.net>
0 siblings, 1 reply; 2+ messages in thread
From: Thierry Missimilly @ 2005-01-03 08:43 UTC (permalink / raw)
To: postgresql <psql-general@postgresql.org>
It seems that my mail never arrive to the mailing list.
Hi,
I have spend some time to read the very interesting feature LISTEN /
NOTIFY. I have found a lot of documentation on how to use in psql but
nothing on how to use in Perl DBI program. I don't know if it works.
I'll be very happy if someone had used it in a Perl script and send me
an example.
Best regards
Thierry Missimilly
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [Fwd: How to use LISTEN / NOTIFY in a Perl program]
@ 2005-01-04 03:19 Michael Fuhr <mike@fuhr.org>
parent: Thierry Missimilly <Thierry.Missimilly@bull.net>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2005-01-04 03:19 UTC (permalink / raw)
To: Thierry Missimilly <Thierry.Missimilly@bull.net>; +Cc: postgresql <psql-general@postgresql.org>
On Mon, Jan 03, 2005 at 09:43:20AM +0100, Thierry Missimilly wrote:
>
> I have spend some time to read the very interesting feature LISTEN /
> NOTIFY. I have found a lot of documentation on how to use in psql but
> nothing on how to use in Perl DBI program. I don't know if it works.
> I'll be very happy if someone had used it in a Perl script and send me
> an example.
Here's a simple example. Set $dbsource, $dbuser, and $dbpass to
appropriate values and start the script, then open a separate
connection to the database and execute "NOTIFY foo". Each time you
do that, the script should print that it received a notification.
#!/usr/bin/perl -T
use strict;
use warnings;
use DBI;
use IO::Select;
$| = 1;
my $dbsource = "dbi:Pg:dbname=test";
my $dbuser = "testuser";
my $dbpass = "testpassword";
my $dbattr = {RaiseError => 1, AutoCommit => 1};
my $dbh = DBI->connect($dbsource, $dbuser, $dbpass, $dbattr);
$dbh->do("LISTEN foo");
my $fd = $dbh->func("getfd");
my $sel = IO::Select->new($fd);
while (1) {
print "waiting...";
$sel->can_read;
my $notify = $dbh->func("pg_notifies");
if ($notify) {
my ($relname, $pid) = @$notify;
my $row = $dbh->selectrow_hashref("SELECT now()");
print "$relname from PID $pid at $row->{now}\n";
}
}
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-01-04 03:19 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-03 08:43 [Fwd: How to use LISTEN / NOTIFY in a Perl program] Thierry Missimilly <Thierry.Missimilly@bull.net>
2005-01-04 03:19 ` Michael Fuhr <mike@fuhr.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox