I have a simple ajax request that can potentially be performed several times in a second. Should I put a pg_close($con) at the end of the php file? Will it open hundreds of connections for each ajax request, or will it use the same one it opened at the beginning of the file with $result = pg_query($con, $query);?
Thanks!
It will close it at the end of the script. Run a connection pooler like pgbouncer between Apache and pg.
See Number of connections in the PostgreSQL wiki.