NOTIFY/LISTEN, PHP, rule vs. trigger, blocking, missed NOTIFY's - Mailing list pgsql-general

From CSN
Subject NOTIFY/LISTEN, PHP, rule vs. trigger, blocking, missed NOTIFY's
Date
Msg-id 20050810005252.71988.qmail@web52906.mail.yahoo.com
Whole thread Raw
List pgsql-general
Scott and I were discussing NOTIFY/LISTEN using a PHP
script here:

http://phpbuilder.com/board/showthread.php?t=10302693

Basically:


PHP Code:
 #!/usr/bin/php -q
<?php
$conn = pg_connect("dbname=test user=user");
pg_query("listen record_deleted");
$interval = 10;
for (;1;){
        sleep($interval);
        $notify = pg_get_notify($conn);
        if ($notify){
                print "Now we do something";
        }
}
?>


And the sql code:

CREATE TABLE ntest ( id serial primary key, path text
);
create table naudit ( id int primary key, path text );
create rule audit_test as on delete to ntest do (
insert into naudit(id,path) values (OLD.id, OLD.path);
notify record_deleted );
insert into ntest (path) values
('/usr/local/lib/php.ini2');
 delete from ntest;


I think he may be off on some wild and exotic vacation
;) or something - so I'll post my questions here too:

* Is there any reason to use a rule rather than a
trigger? I guess a rule is just simpler.

* Also, think there's any way to just have the PHP
script block until a notify event is actually
received, rather than checking every [sleep] seconds?

* Finally, PG's docs on notify say that if events
happen in rapid succession, notify's might get
dropped. For example: could many item rows get
deleted, but some of their corresponding files not get
deleted due to dropped notify's?

Thanks,
CSN

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

pgsql-general by date:

Previous
From: SCassidy@overlandstorage.com
Date:
Subject: Re: Suppressing Error messages.
Next
From: merlyn@stonehenge.com (Randal L. Schwartz)
Date:
Subject: Re: Poll on your LAPP Preferences