【发布时间】:2013-07-24 04:45:25
【问题描述】:
我正在我的一门课程中扩展 mysqli。它工作得很好,但连接增加了大约 1 秒的 php 加载时间。我想知道是否有更快或更合适的方式连接到 MySql,或者是否可以构建数据库增强功能以加快执行速度?
1 秒的开销纯粹是我的 WAMP 服务器上的连接,这是在我运行任何其他查询之前。
有什么想法吗?
谢谢
class db extends mysqli {
//ACCESS VARIABLES FOR ENTIRE SITE
protected $_host = 'myhost';
protected $_user = 'myuser';
protected $_pass = 'mypass';
protected $_db = 'mydb';
function __construct() {
echo microtime(true)."<br />";
parent::__construct($this->_host, $this->_user, $this->_pass, $this->_db);
if ($this->connect_errno) die('Connect Error: ' . $this->connect_errno);
$this->set_charset("utf8");
echo microtime(true)."<br />";
}
}
【问题讨论】:
-
如果您使用的是 Windows,我总是发现 Windows 的 WAMP/XAMP 速度非常慢...您确定您的扩展程序会“增加”加载时间吗? (
new mysqli(params...)有多快) -
尝试使用 IP 地址而不是主机。可能是 DNS 问题。