目錄表

增進 MySQL 或 PHP 的效能

High Performance MySQL

http://highperformancemysql.com

Simple Optimization for PHP and MySQL

http://www.dublish.com/articles/10.html

MySQL

PHP

      <?
         ...
         ...
         ...
      ?>     

is faster than

      <? ... ?>
      <? ... ?>
      <? ... ?>    
      "SELECT id FROM tabell WHERE id = $_SESSION[id] LIMIT 1"    

is faster than:

      "SELECT id FROM tabell WHERE id = ".$_SESSION['id']." LIMIT 1"    
      'SELECT id FROM tabell WHERE id =
      '.$_SESSION['id'].' LIMIT 1'     

as the fastest way of concatenating querys.

    echo "echoing ",$variable," something";

Note: This only works with echo, which is a function that can take several strings as arguments.

      $maxvalue = 100/10;
      for($i=0; $i<$maxvalue; $i++){
         // Some code
      }    

is faster than:

      for($i=0; $i<100/10; $i++){
         // Some code
      }    

because the value is calculated once instead of ten times.

If possible it's of course always better to generate static html pages every time something is updated or as often as an update might be relevant instead of querying the database every time.

Further reading