我的学说真的很慢.简单查询,一秒出结果 [英] My doctrine is Really Slow. Simple query and one second to get the result

查看:60
本文介绍了我的学说真的很慢.简单查询,一秒出结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:
Windows Server 2008 R2
MySql 5.1.562
PHP 5.3.2
教义 1.2

Here is my setup:
Windows Server 2008 R2
MySql 5.1.562
Php 5.3.2
Doctrine 1.2

任何人都知道为什么我的查询需要大约一秒钟才能执行一个简单的查询.

Anybody have an Idea why my query is taking about one second to perform a simple query.

echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />";

             $q = Doctrine_Query::create()
            ->from("Ordering")
            ->where("client_id = ?",array($_SESSION["UserID"]));

            $ResProduct = $q->execute();

echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />";  

这里是 2 echo 的结果,向您展示执行查询需要多长时间.

Here is the result of the 2 echo to show you how long it's take to perform the query.

2011-04-21 01:48:24::::::1303364904.8051
2011-04-21 01:48:25::::::1303364905.8418

另外一点,数据库中没有数据.

An other thing, there is no data in the database.

编辑
我直接在mysql控制台执行查询,很快得到结果

Edit
I Perform the query directly in the mysql console and get the result very quickly

mysql> select * from Ordering where client_id = 2;
+----+------------+-------+------+-----------+
| id | product_id | price | qty  | client_id |
+----+------------+-------+------+-----------+
|  7 |          1 |  0.89 |   20 |         2 |
+----+------------+-------+------+-----------+
1 row in set  (0.00 sec)

推荐答案

  • 使用 microtime(true) 代替 microtime_float()
  • 配置 MySQL 不解析连接客户端的 IP:http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-name-resolve
  • client_id = ?- 为什么将 $_SESSION["UserID"] 转换为数组?我认为这是不必要的.
    • Use microtime(true) instead of microtime_float()
    • Configure MySQL not to resolve IP's of connecting clients: http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-name-resolve
    • client_id = ?- why do you cast $_SESSION["UserID"] to array? I think this is unnecessary.
    • 这篇关于我的学说真的很慢.简单查询,一秒出结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆