PHP连接MySQL的典型速度是多少?

发布于 2024-10-04 16:25:08 字数 346 浏览 0 评论 0原文

假设我有非常标准的 mysql 连接代码:

$dbhost = '192.168.1.99';
$dbuser = 'dbuser';
$dbpass = 'dbuserpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);

这将从 Web 服务器连接到数据库服务器(假设 Web 服务器位于 192.168.1.98 或其他)。通常,上述代码会运行多长时间?目前,我看到大约 2 秒。这么慢吗?

Say I have very standard mysql connection code:

$dbhost = '192.168.1.99';
$dbuser = 'dbuser';
$dbpass = 'dbuserpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);

This would connect from the web server to the database server (say the web server is at 192.168.1.98 or something). Typically, how long would the above code run? Currently, I'm seeing about 2 seconds. Is that slow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

唠甜嗑 2024-10-11 16:25:08

一种可能性是 mysql 正在执行 DNS 查找以查找连接服务器的名称;根据您的设置,这可能需要很长时间。除了能够通过主机名而不是 IP 地址指定用户(例如 user@example.com 而不是 user< /code>@192.168.1.1)。

可以在配置中或使用 --skip-name-resolve 参数启动 MySQL 时禁用此功能。更多信息请参见MySQL 站点

One possibility is that mysql is doing a DNS lookup to find the name of the connecting server; depending on your setup, this could take a long time. There's not really much benefit to it, aside from being able to specify the users by hostname rather than IP address (e.g. user@example.com rather than user@192.168.1.1).

This can be disabled in the configuration or when starting up MySQL with the --skip-name-resolve parameter. More information is available on the MySQL site.

请恋爱 2024-10-11 16:25:08

2秒确实看起来慢,但这取决于你的服务器和数据库服务器。根据他们正在做的其他事情、他们所在的位置以及许多其他因素,它实际上可能会很快。

我通常得到的时间不到一秒。

2 seconds does seem slow, but it depends on your server and database server. Depending on what else they are doing, where they are located and many other factors it could actually be fast.

I usually get times of less than a second.

没︽人懂的悲伤 2024-10-11 16:25:08

对于本地 LAN,除非您使用过时的设备,或者出现问题,否则通常应为 (a) 毫秒的量级。

For local LAN, unless you're using antiquated equipment, or something is wrong, it should typically be on the order of (a) millisecond(s).

迷荒 2024-10-11 16:25:08

你们有很多桌子吗?连接后可能会花时间四处查看。命令行mysql客户端也很慢吗?如果您从本地主机连接,速度快吗?

Do you have lots of tables? It may be spending time looking around after connecting. Is the command line mysql client slow too? Is it fast if you're connecting from localhost?

总攻大人 2024-10-11 16:25:08

非常慢。在一般网站上,整个页面会在两秒内呈现。即,连接到数据库、运行查询、检索结果并呈现页面。

That is very slow. On avarage websites, the entire page renders within two seconds. That is, connecting to the database, running the queries, retrieving results and rendering the page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文