This is due to the configuration of PHP.ini, if the pgsql.allow_persistent label is set to true then pg_close will not close the connection because it is persistent, otherwise if you set it to false, pg_close will close the connection.
The documentation says pg-pconnect :
pg_close() will not close persistent links generated by pg_pconnect()
source share