简体   繁体   English

远程数据库查询缓慢

[英]Slow query on remote database

I have: 我有:

  • A linux server with PHP 5.3.2 and Apache 2.0 具有PHP 5.3.2和Apache 2.0的Linux服务器
  • A windows Server with SQL SERVER 具有SQL SERVER的Windows Server

I connect my linux server with database with unixODBC 2.3.1 and FREETDS 0.9.1 我将Linux服务器与具有unixODBC 2.3.1和FREETDS 0.9.1的数据库连接

The connection is okay but the queries are slow. 连接正常,但查询速度很慢。 Here is my code that generate the image below: 这是生成下面图像的代码:

$this->adodb->LogSQL(true); // turn on logging
$query = "select c.name, t.name, c.length from syscolumns c join systypes t on t.xusertype = c.xusertype
          join sysobjects o on o.id=c.id where o.name = 'CONDOMINIO'";
$res = $this->adodb->Execute($query);
$this->adodb->LogSQL(false); // turn off logging
$perf = NewPerfMonitor($this->adodb);
echo $perf->SuspiciousSQL();
echo $perf->ExpensiveSQL();

Image http://www.vigoonline.net/slow.png 图片http://www.vigoonline.net/slow.png

As you can see, the first query has an average time of 4.68 seconds, which is way too slow. 如您所见,第一个查询的平均时间为4.68秒,太慢了。

If I execute the same query like this: 如果我像这样执行相同的查询:

$this->adodb->_query($query);

Then the time to execute the query takes less than a second what is great. 然后,执行查询的时间不到一秒钟,这真是太棒了。 Has anyone else experienced the same thing? 有没有其他人经历过同样的事情?

The query called with "Execute" is used for the own class for bringing the "MetaColumns" information from the table 使用“ Execute”调用的查询用于自己的类,以从表中获取“ MetaColumns”信息

The table "CONDOMINIO" only has 21 rows. 表“ CONDOMINIO”仅具有21行。

If the server database is in the same machine with the application script, then the response is fast! 如果服务器数据库与应用程序脚本位于同一台计算机上,则响应速度很快!

I resolved this myself. 我自己解决了。 Here is what I did: 这是我所做的:

Go to the file /adodb/drivers/adodb-odbc.inc.php and to the class ADODB_odbc 转到文件/adodb/drivers/adodb-odbc.inc.php并转到类ADODB_odbc

Here try to find: 在这里尝试找到:

var $curmode = SQL_CUR_USE_DRIVER

and change it to: 并将其更改为:

var $curmode = SQL_CUR_USE_IF_NEEDED;

This will make the connection use SQL_CUR_USE_ODBC when needed and "Voila" DB access speed to SQL server is really fast! 这将使连接在需要时使用SQL_CUR_USE_ODBC ,并且对SQL Server的“ Voila” DB访问速度确实非常快!

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

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