I’ve searched the web looking for a way to connect a PHP application to PostgreSQL by Unix sockets using the
pg_connect() function, but I didn’t find an answer to my situation.
Today using the trial and error method, I found a solution. There’s two ways to do the connection, since you have Unix socket connection enabled in your server:
1) Using the socket path:
<?php $conn = pg_connect('host=/var/run/postgresql user=[...] bdname=[...]'); ?>
2) Omitting the host name/path:
<?php $conn = pg_connect('user=[...] bdname=[...]'); ?>
Note: In this case (omitting the host name) the default socket path will be used, probrably that set on postgres.conf file.