Ir al contenido

Database connection not closed (ARCH7084)

Esta página aún no está disponible en tu idioma.

Key php.performance.db-connection-not-closed · Severity error · Category performance

A database connection or cursor that is opened but never released exhausts the pool and leaks connections. Close it or return it to the pool when done.

<?php
function rowCount(): int
{
$conn = pg_connect('host=db dbname=app');
$res = pg_query($conn, 'SELECT count(*) FROM users');
return (int) pg_fetch_result($res, 0, 0);
}
<?php
function rowCount(): int
{
$conn = pg_connect('host=db dbname=app');
$res = pg_query($conn, 'SELECT count(*) FROM users');
$count = (int) pg_fetch_result($res, 0, 0);
pg_close($conn);
return $count;
}

Close connections and cursors with a call like pg_close() as soon as work finishes, returning them to the pool.