php8.5
Home/ Manual/ pgsql / functions/ pg_ping

pg_ping

PHP function Edit on GitHub ✎

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

Ping database connection

Description

pg_ping(PgSql\Connection|null $connection = null): bool

pg_ping() pings a database connection and tries to reconnect it if it is broken.

Parameters

connection

Connection-with-nullable-default

Return Values

Success

Changelog

VersionDescription
8.0.0connection is now nullable.

Examples

pg_ping() example

php
<?php 
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
  echo "An error occurred.\n";
  exit;
}

if (!pg_ping($conn))
  die("Connection is broken\n");
?>

See Also

Source: reference/pgsql/functions/pg-ping.xml · from the official PHP manual (php/doc-en)