简体   繁体   English

Php - 连接到远程数据库非常慢

[英]Php - Connecting to remote database very slow

I have a new VPS server, and I'm trying to get it to connect to another server at the same ISP. 我有一个新的VPS服务器,我试图让它连接到同一ISP的另一台服务器。 When I connect via mysql's command line tool, the connection is very fast. 当我通过mysql的命令行工具连接时,连接速度非常快。

When I use PHP to connect to the remote DB, the connection time may take up to 5 seconds. 当我使用PHP连接到远程数据库时,连接时间可能需要5秒。 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. 这不仅限于mysql,使用file_get_contents()从几乎任何其他服务器下载文件都会产生相同的延迟。 Using wget to get the file does not have this lag. 使用wget获取文件没有这种滞后。

I timed DNS queries from within PHP using dns_get_record(), and these are fast (1-2 milliseconds). 我使用dns_get_record()从PHP中定时DNS查询,这些是快速的(1-2毫秒)。

Any thoughts on what in the php config may be causing this? 有关php配置中的内容可能导致此问题的任何想法?

Thanks. 谢谢。

I would check to see what mode PHP is running in, is it for some reason running the scripts as a CGI. 我会检查PHP运行的模式,是出于某种原因将脚本作为CGI运行。 Basically is PHP itself really slow, and its only noticeable when running remote operations. 基本上PHP本身真的很慢,而且在运行远程操作时它才会引人注目。

Check the web server's configuration. 检查Web服务器的配置。 Also if it's an option, try PHP from the command line and see if it performs better without the web server layer involved. 此外,如果它是一个选项,请从命令行尝试PHP,看看它是否在没有涉及Web服务器层的情况下表现更好。

I ended up upgrading from PHP 5.1.6 to PHP 5.2.6, and the problem went away. 我最终从PHP 5.1.6升级到PHP 5.2.6,问题就消失了。 It definitely was a DNS lookup issue within PHP, the following would take about 5 seconds to run: 它肯定是PHP中的DNS查找问题,以下大约需要5秒才能运行:

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. 我有一种感觉IPV6是一个问题(大多数是在网上阅读这个预感),但我没有任何证据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM