Zend Framework and Mysql - very slow

前端 未结 3 1578
感动是毒
感动是毒 2020-12-16 08:10

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 sq

相关标签:
3条回答
  • 2020-12-16 09:03

    Tips:

    • 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).

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

      mysql> EXPLAIN SELECT * FROM standard_accessory WHERE model = 'abc';
      
    • 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'));
      
    • 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?

    0 讨论(0)
  • 2020-12-16 09:10

    The easiest way to debug this, is to profile your sql queries. you can use Firephp (plugin for firebug) see http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug

    another way to speed up things a little is to cache the metadata of your tables. see: http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.metadata.caching

    0 讨论(0)
  • 2020-12-16 09:10

    Along with the above suggestions I did a very unscientific test and found that the PDO adapter was faster for me in my application (I know mysqli is supposed to be faster but maybe it's the ZF abstraction). I show the results here (the times shown are only good for comparison)

    0 讨论(0)
提交回复
热议问题