Closed ParkFramework closed 8 years ago
I think ext-pq should do this through PGEventConnReset
handling. We're providing facilities for listeners and prepared statements, so we should also handle availability of them after a connection reset (which is not always user-induced).
After resetAsync
or remote disconnect, event reset
not fire
After resetAsync or remote event reset not fire
Can you elaborate? I didn't understand that sentence (especially the occurrence of "remote").
Can you elaborate? I didn't understand that sentence (especially the occurrence of "remote").
Sorry I mean - remote disconnect
Why should the restore logic not fire when a remote disconnect happens?
Why should the restore logic not fire when a remote disconnect happens?
I mean:
$connection->on(pq\Connection::EVENT_RESET, function() {
// never executed, after resetAsync() or remote disconnect PostgreSQL server
});
Is bug?
Probably, let me check!
Thank you.
Seems to work here. Keep in mind you have to use the first method presented here to complete async connect/reset.
$c = new pq\Connection(PQ_DSN);
$c->on(pq\Connection::EVENT_RESET, function($conn) {
var_dump($conn);
});
$c->resetAsync();
// wait until the stream becomes writable
$w = array($c->socket);
$r = $e = null;
if (stream_select($r, $w, $e, null)) {
// loop until the connection is established
while (true) {
switch ($c->poll()) {
case pq\Connection::POLLING_READING:
// we should wait for the stream to be read-ready
$r = array($c->socket);
stream_select($r, $w, $e, NULL);
break;
case pq\Connection::POLLING_WRITING:
// we should wait for the stream to be write-ready
$w = array($c->socket);
$r = $e = null;
stream_select($r, $w, $e, null);
break;
case pq\Connection::POLLING_FAILED:
printf("Connection failed: %s\n", $c->errorMessage);
break 2;
case pq\Connection::POLLING_OK:
printf("Connection completed\n");
break 2;
}
}
}
Seems to work here. Keep in mind you have to use the first method presented here to complete async connect/reset.
Yes EVENT_RESET
is working.
Problem was in my code, not your bug, sorry.
We plan to implement in the application layers, restore
listeners
andstatements
, afterConnection::reset
.Or perhaps it is better if it is implemented in
ext-pq
?