2 restore listeners on reset
15 $c = new pq\Connection(PQ_DSN);
17 $c->listen("notify", function($channel, $message) {
18 printf("%s: %s\n", $channel, $message);
20 $c->on(pq\Connection::EVENT_RESET, function($conn) {
21 printf("Connection was reset\n");
23 $c->notify("notify", "Gotcha!");
26 // wait until the stream becomes writable
27 $w = array($c->socket);
30 if (stream_select($r, $w, $e, null)) {
32 // loop until the connection is established
37 case pq\Connection::POLLING_READING:
38 // we should wait for the stream to be read-ready
39 $r = array($c->socket);
40 stream_select($r, $w, $e, NULL);
43 case pq\Connection::POLLING_WRITING:
44 // we should wait for the stream to be write-ready
45 $w = array($c->socket);
47 stream_select($r, $w, $e, null);
50 case pq\Connection::POLLING_FAILED:
51 printf("Connection failed: %s\n", $c->errorMessage);
54 case pq\Connection::POLLING_OK:
55 printf("Connection completed\n");
60 $c->notify("notify", "Do you miss me?");
69 notify: Do you miss me?