views:

949

answers:

2

I have a new VPS server, and I'm trying to get it to connect to another server at the same ISP. When I connect via mysql's command line tool, the connection is very fast.

When I use PHP to connect to the remote DB, the connection time may take up to 5 seconds. Queries after this are executed quickly.

This is not limited to mysql, using file_get_contents() to download a file from nearly any other server gives the same lag. Using wget to get the file does not have this lag.

I timed DNS queries from within PHP using dns_get_record(), and these are fast (1-2 milliseconds).

Any thoughts on what in the php config may be causing this?

Thanks.

+2  A: 

I would check to see what mode PHP is running in, is it for some reason running the scripts as a CGI. Basically is PHP itself really slow, and its only noticeable when running remote operations.

Check the web server's configuration. Also if it's an option, try PHP from the command line and see if it performs better without the web server layer involved.

acrosman
+1  A: 

I ended up upgrading from PHP 5.1.6 to PHP 5.2.6, and the problem went away. It definitely was a DNS lookup issue within PHP, the following would take about 5 seconds to run:

gethostbyname('example.com')

I have a feeling IPV6 was an issue (mostly a hunch from reading about this online), but I don't have any proof.

Jay