Search Postgresql Archives

NOTIFY/LISTEN, PHP, rule vs. trigger, blocking, missed NOTIFY's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux