function sighandler($signo) { global $conn; echo "SIGNAL CAUGHT, ABORTING QUERY\n"; pg_cancel_query($conn); exit; }
/** * Connection constructor. * * @param resource $handle PostgreSQL connection handle. * @param resource $socket PostgreSQL connection stream socket. */ public function __construct($handle, $socket) { $this->handle = $handle; $this->poll = Loop\poll($socket, static function ($resource, bool $expired, Io $poll) use($handle) { /** @var \Icicle\Awaitable\Delayed $delayed */ $delayed = $poll->getData(); if (!\pg_consume_input($handle)) { $delayed->reject(new FailureException(\pg_last_error($handle))); return; } if (!\pg_connection_busy($handle)) { $delayed->resolve(\pg_get_result($handle)); return; } $poll->listen(); // Reading not done, listen again. }); $this->await = Loop\await($socket, static function ($resource, bool $expired, Io $await) use($handle) { $flush = \pg_flush($handle); if (0 === $flush) { $await->listen(); // Not finished sending data, listen again. return; } if (false === $flush) { /** @var \Icicle\Awaitable\Delayed $delayed */ $delayed = $await->getData(); $delayed->reject(new FailureException(\pg_last_error($handle))); } }); $this->onCancelled = static function () use($handle) { \pg_cancel_query($handle); }; $this->executeCallback = function (string $name, array $params) : \Generator { return $this->createResult(yield from $this->send('pg_send_execute', $name, $params)); }; }