pg_connect花费的时间超过5秒?

时间:2010-01-09 19:57:45

标签: php postgresql performance

我刚刚设置了一个运行PHP的OpenBSD小型个人开发服务器,它带有几乎默认的(启用的调试消息)php.ini,并使用默认配置安装了PostgreSQL。

好吧,运行这个非常简单的代码

$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";

结果是“在6.xxs中生成。为什么简单地建立数据库需要6秒钟?使用PgAdmin3,连接根本不需要任何时间。

我想在这里使用持久连接吗?还是unix-socket还是什么?

2 个答案:

答案 0 :(得分:1)

如果你

,这也会发生吗?

a)使用127.0.0.1而不是localhost
  b)使用unix socket

连接到postgresql服务器?
您的OpenBSD,DNS,Postgresql服务器和/或php是否配置为使用ipv6?

答案 1 :(得分:0)

在同一台计算机上telnet localhost 5432尝试查看问题是否与PostgreSQL相关。