Optimize PHP, Apache & MySQL for performance

Two MySQL tuner scripts

MySQLTuner (Perl) and MySQL Performance Tuning Primer (Shell) are two scripts that can help diagnose MySQL database performance issues, and provide recommendations on how to solve them.  While both scripts output similar information, the diagnosis can be slightly different with each script, so I like to use both.  Below are directions on how to use them, as well as a few screenshots.

# Download MySQLTuner and MySQL Performance Tuning Primer to ~/scripts.
# To avoid having to invoke Perl/SH each time, make both files executable.
chmod +x ~/scripts/mysqltuner.pl
chmod +x ~/scripts/tuning-primer.sh

# After that, give them a go!
~/scripts/mysqltuner.pl
~/scripts/tuning-primer.sh

tuning-primer.sh

Configure Apache, PHP, and MySQL for performance

Make sure that your configuration files are setup correctly for your server, application, and load.  Enough said?

Best Practices

Did you know that incrementing a class variable is three times slower than incrementing a local variable?  Did you know adding LIMIT 1 to SQL queries for a single row can speed up queries?  Simply changing the way you write code can speed things up considerably.

Get a PHP opcode cache

PHP is an interpreted language, and as such it must be “compiled” into a readable format called opcode.  An opcode cache basically preserves the compiled data, and allows us to essentially skip a step.  This can save much needed resources (CPU, memory, etc.), and lower load time considerably.

5 thoughts on “Optimize PHP, Apache & MySQL for performance”

  1. Pingback: abcphp.com
  2. Just a quick correction – Zend Optimizer is a loader for Zend Guard encoded scripts. It also does some runtime optimizations, but is not an opcode cache.

    Zend Optimizer+ (note the “+”) is an opcode cache and is available as part of Zend Server and Zend Server CE (both of which contain other technologies for optimizing performance).


  3. David Goulden (Zend):

    Just a quick correction – Zend Optimizer is a loader for Zend Guard encoded scripts. It also does some runtime optimizations, but is not an opcode cache.

    Zend Optimizer+ (note the “+”) is an opcode cache and is available as part of Zend Server and Zend Server CE (both of which contain other technologies for optimizing performance).

    Thanks David! I made that correction within the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>