sql-server - 如何加速 mssql_connect()

标签 sql-server database performance sql-server-2008 php-5.2

我正在从事一个 PHP 对话系统与 Microsoft SQL Server 2008 通信的项目,我需要在 PHP 端提高速度。

在分析我的 PHP 脚本后,我发现在该特定系统上调用 mssql_connect() 需要大约 200 毫秒。对于一些简单的对话框,这大约是整个脚本运行时间的 60%。因此,我可以通过加快此调用来获得巨大的性能提升。

我已经确保为我的 PHP 脚本的每个请求只生成一个连接句柄。

有没有办法加快与 SQL Server 的初始连接?但有一些限制:

  • 我不会使用 PDO(这里有很多遗留代码无法使用它)
  • 我无权访问 SQL Server 配置,因此我需要一个 PHP 端解决方案
  • 我无法升级到 PHP 5.3.X,同样是因为糟糕的遗留代码。

最佳答案

嗯。我不太了解 MS SQL,但优化单个调用可能很困难。

想到的一件事是尝试 mssql_pconnect() ,当然:

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

但您可能已经想到了这一点。

第二件事,你不是说 MS SQL 是否与 PHP 部分在同一台机器上运行,但如果不是,可能手头有一个基本的网络问题?一台主机与另一台主机之间的经典 ping 有多快?对于未完美配置的虚拟机也是如此。 200 毫秒真的听起来非常非常慢。

然后,在 mssql_connect() 的用户注释中,有 talk关于 MS SQL 的 native PHP 驱动程序。我对此一无所知,无论它是否属于“旧”语法以及它是否适用于您的情况,但它可能值得一看。

用户贡献的笔记总是值得一看,有像this one这样的花絮。 :

Just in case it helps people here... We were being run ragged by extremely slow connections from IIS6 --> SQL Server 2000. Switching from CGI to ISAPI fixed it somewhat, but the initial connection still took along the lines of 10 seconds, and eventually the connections wouldn't work any more.

The solution was to add the database server IP address to the HOST file on the server, pointing it to the internal machine name. Looks like some kind of DNS lookup was the culprit.

Now connections and queries are flying, and the world is once again right.

关于sql-server - 如何加速 mssql_connect(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2281521/

相关文章:

sql - 如何从 sql server 将数据导入 mongodb?

sql - 如何正确分组这个表?

C++ 日志记录和性能调整库

sql - varbinary(16) 上的 ANSI_PADDING 不起作用

mysql - 将 SQL 主键限制在特定范围内

c# - Entity Framework Core 5 : configuring many to many relationships, 如何指定外键名称

php - 当我尝试从 MySQL 检索信息时,我的页面崩溃了

c - 如何使用 OpenMP 并行化在矩阵上进行迭代的 while 循环?

android - 如何在后台线程上运行 ListenableWorker 工作?

sql - 在 SQL Server 的更新语句中使用随机记录更新表?