参考

User Contributed Notes 4 notes

There is no way to poll/wait for a notification to come in. You either have to enter a busy loop or sleep. Both options are horrible. It would be nice for PHP to provide access to PQsocket so one could select() on the socket connection. This is how it's done from C or Perl.

It might seem that after calling pg_get_result() upon sending just a single query, the connection will not be busy. The correct way is, though, to call extra pg_get_result() in a loop until it returns false [1].

/* The following does not seem necessary for good queries, but is vital for erroneous queries. Commenting the loop out leads to this script fail with the "Connection is busy" error. */while (pg_get_result($conn));

william at 25thandClement dot com said: "There is no way to poll/wait for a notification to come in. .."Yes, there is. If there is a query in progress, pg_get_result() will block and return the result of that query when it's complete.