Search Postgresql Archives

Re: Is there any way to listen to NOTIFY in php without polling?

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

 



	Misa Simic wrote:

> I am not a C developer - was not aware about select()... I was read it as
> some kind of sleep...

php provides socket_select() as an equivalent to C's select().
See http://php.net/manual/en/function.socket-select.php

But it takes "socket resources" as arguments and the postgres php layer
does not provides a conversion from the file descriptor returned by
PQsocket() to such php socket resources.
Thus socket_select() can't be used to monitor a postgres connection.

However, you can get a behavior that's close enough in practice to
select() with code like this:

pg_query($conn, "LISTEN event_name");
while (!$end) {
  $arr=pg_get_notify($conn);
  if (!$arr) {
    usleep(100000);
  }
  else
    // process the notification
}

This will catch a notification 1/10 second max after it's available and sleep
the rest of the time.

Best regards,
-- 
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[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