• <tfoot id='Ux2B7'></tfoot>

  • <legend id='Ux2B7'><style id='Ux2B7'><dir id='Ux2B7'><q id='Ux2B7'></q></dir></style></legend>
    <i id='Ux2B7'><tr id='Ux2B7'><dt id='Ux2B7'><q id='Ux2B7'><span id='Ux2B7'><b id='Ux2B7'><form id='Ux2B7'><ins id='Ux2B7'></ins><ul id='Ux2B7'></ul><sub id='Ux2B7'></sub></form><legend id='Ux2B7'></legend><bdo id='Ux2B7'><pre id='Ux2B7'><center id='Ux2B7'></center></pre></bdo></b><th id='Ux2B7'></th></span></q></dt></tr></i><div id='Ux2B7'><tfoot id='Ux2B7'></tfoot><dl id='Ux2B7'><fieldset id='Ux2B7'></fieldset></dl></div>
  • <small id='Ux2B7'></small><noframes id='Ux2B7'>

      <bdo id='Ux2B7'></bdo><ul id='Ux2B7'></ul>

        Zend Framework 和 Mysql - 非常慢

        Zend Framework and Mysql - very slow(Zend Framework 和 Mysql - 非常慢)

          <tfoot id='THMdO'></tfoot>
          <i id='THMdO'><tr id='THMdO'><dt id='THMdO'><q id='THMdO'><span id='THMdO'><b id='THMdO'><form id='THMdO'><ins id='THMdO'></ins><ul id='THMdO'></ul><sub id='THMdO'></sub></form><legend id='THMdO'></legend><bdo id='THMdO'><pre id='THMdO'><center id='THMdO'></center></pre></bdo></b><th id='THMdO'></th></span></q></dt></tr></i><div id='THMdO'><tfoot id='THMdO'></tfoot><dl id='THMdO'><fieldset id='THMdO'></fieldset></dl></div>
            <tbody id='THMdO'></tbody>

          • <small id='THMdO'></small><noframes id='THMdO'>

              <bdo id='THMdO'></bdo><ul id='THMdO'></ul>
              <legend id='THMdO'><style id='THMdO'><dir id='THMdO'><q id='THMdO'></q></dir></style></legend>
                  本文介绍了Zend Framework 和 Mysql - 非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 php、mysql 和 zend 框架创建一个网站.当我尝试运行任何 sql 查询时,页面生成会跳转到 0.5 秒左右.那太高了.如果我关闭 sql,页面生成为 0.001.我运行的查询量并没有真正影响页面生成时间(测试了 1-10 个查询).停留在 0.5 秒我不明白,我做错了什么.

                  I am creating a web site using php, mysql and zend framework. When I try to run any sql query, page generation jumps to around 0.5 seconds. That's too high. If i turn of sql, page generation is 0.001. The amount of queries I run, doesn't really affect the page generation time (1-10 queries tested). Stays at 0.5 seconds I can't figure out, what I am doing wrong.

                  我在引导程序中连接到 sql:

                  I connect to sql in bootstrap:

                  protected function _initDatabase ()
                  {
                      try
                      {
                          $config = new Zend_Config_Ini( APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV );
                          $db = Zend_Db::factory( $config -> database);
                          Zend_DB_Table_Abstract::setDefaultAdapter( $db );
                      }
                      catch ( Zend_Db_Exception $e )
                      {
                  
                      }
                  }
                  

                  然后我有一个简单的模型

                  Then I have a simple model

                  class StandardAccessory extends Zend_DB_Table_Abstract
                  {
                      /**
                       * The default table name 
                       */
                      protected $_name = 'standard_accessory';
                  
                      protected $_primary = 'model';
                  
                      protected $_sequence = false;
                  }
                  

                  最后,在我的索引控制器中,我只运行了 find 方法.

                  And finally, inside my index controller, I just run the find method.

                  require_once APPLICATION_PATH . '/models/StandardAccessory.php';
                      $sa = new StandardAccessory( );
                      $stndacc = $sa->find( 'abc' );
                  

                  所有这一切都需要大约 0.5 秒,这太长了.有什么建议?

                  All this takes ~0.5 seconds, which is way too long. Any suggestions?

                  谢谢!

                  推荐答案

                  提示:

                  • 缓存表元数据.默认情况下,每次实例化表对象时,Zend_Db_Table 都会尝试发现有关该表的元数据.使用缓存来减少它必须执行此操作的次数.或者在您的 Table 类中对其进行硬编码(注意:db 表不是模型).

                  • Cache the table metadata. By default, Zend_Db_Table tries to discover metadata about the table each time your table object is instantiated. Use a cache to reduce the number of times it has to do this. Or else hard-code it in your Table class (note: db tables are not models).

                  使用EXPLAIN 分析MySQL的优化方案.它是否有效地使用了索引?

                  Use EXPLAIN to analyze MySQL's optimization plan. Is it using an index effectively?

                  mysql> EXPLAIN SELECT * FROM standard_accessory WHERE model = 'abc';
                  

                1. 使用BENCHMARK() 来衡量查询的速度,不使用PHP.子查询必须返回单列,所以一定要返回一个非索引列,这样查询必须接触数据,而不是只返回一个索引条目.

                2. Use BENCHMARK() to measure the speed of the query, not using PHP. The subquery must return a single column, so be sure to return a non-indexed column so the query has to touch the data instead of just returning an index entry.

                  mysql> SELECT BENCHMARK(1000, 
                    (SELECT nonindexed_column FROM standard_accessory WHERE model = 'abc'));
                  

                3. 请注意,当您进行第一次查询时,Zend_Db_Adapter 会延迟加载其数据库连接.因此,如果连接到 MySQL 服务器时出现任何缓慢,当您实例化 Table 对象时(当它查询元数据时)就会发生这种情况.任何原因这可能需要很长时间?DNS 查找,也许?

                4. Note that Zend_Db_Adapter lazy-loads its db connection when you make the first query. So if there's any slowness in connecting to the MySQL server, it'll happen as you instantiate the Table object (when it queries metadata). Any reason this could take a long time? DNS lookups, perhaps?

                  这篇关于Zend Framework 和 Mysql - 非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!
                5. 相关文档推荐

                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)
                  MySQL cumulative sum grouped by date(按日期分组的 MySQL 累计总和)

                    <tbody id='pNgYD'></tbody>

                  <small id='pNgYD'></small><noframes id='pNgYD'>

                  <tfoot id='pNgYD'></tfoot>
                6. <legend id='pNgYD'><style id='pNgYD'><dir id='pNgYD'><q id='pNgYD'></q></dir></style></legend>
                  <i id='pNgYD'><tr id='pNgYD'><dt id='pNgYD'><q id='pNgYD'><span id='pNgYD'><b id='pNgYD'><form id='pNgYD'><ins id='pNgYD'></ins><ul id='pNgYD'></ul><sub id='pNgYD'></sub></form><legend id='pNgYD'></legend><bdo id='pNgYD'><pre id='pNgYD'><center id='pNgYD'></center></pre></bdo></b><th id='pNgYD'></th></span></q></dt></tr></i><div id='pNgYD'><tfoot id='pNgYD'></tfoot><dl id='pNgYD'><fieldset id='pNgYD'></fieldset></dl></div>

                            <bdo id='pNgYD'></bdo><ul id='pNgYD'></ul>