views:

56

answers:

2

Hello, I have just setup a OpenBSD little personal development server running PHP with an almost-default(enabled debugging messages) php.ini and installed PostgreSQL with the default configuration.

Well, running this very simple code

$starttimer=time()+microtime();

$dbconn = pg_connect("host=localhost port=5432 dbname=earlzblog_001 user=xxx password=xxx")
    or die("Couldn't Connect".pg_last_error());
pg_close($dbconn);
$stoptimer = time()+microtime();
echo "Generated in ".round($stoptimer-$starttimer,4)." s";

the result is "generated in 6.xxs. Why is it taking 6 seconds to simply make a database connection? Using PgAdmin3, the connections don't take any time at all.

Am I suppose to be using persistent connections here? Or unix-sockets or something?

A: 

Try, from the same machine, telnet localhost 5432 to see if the problem is PostgreSQL-specific or not.

bortzmeyer
no, it's not postgres specific. as I said, pgadmin connects very quickly and doing that telnet thing connects very quickly.
Earlz
+1  A: 

Does this also happen if you

a) use 127.0.0.1 instead of localhost
b) use a unix socket

to connect to the postgresql server?
Is your OpenBSD, DNS, Postgresql server and/or php configured to use ipv6?

VolkerK
wow. I'm not sure why but using `localhost` instead of `127.0.0.1` is what causes the major slow down... it is specific to PHP still though... and nothing was configured to use IPv6..
Earlz
Just out of curiosity: What's the exact output (includeing error/warning messages) for `<?php echo inet_ntop(str_repeat(chr(0), 15).chr(1));` on your machine?
VolkerK