If you are like me happenly working on your macBook doing MAMP (Mac Apache Mysql PHP) developments. Then you do that for a reason and that is heaving it very convenient always how your development platform at hand, and teh second reason might be you need speed!
However my versions of php5 downloaded from here and MySQL version 5 downloaded from here where not rely optimized for speed. Time to do some optimalizations.
There are basicly two areas that can be optimized
First run mysql with this command:
/usr/local/mysql/bin/mysql
Then check the status of the query cache:
mysql> SHOW STATUS LIKE 'Qcache%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 0 |
| Qcache_free_memory | 0 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 0 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 0 |
+-------------------------+----------+
8 rows in set (0.00 sec)
Also shows all zero? In that case the query cache might not have been activate.
My mysql version 5 was installed in the directory /usr/local/mysql/support-files and in the directory we have a support-files/ directory. Really convenient I could copy the my-large.cnf file to /etc/my.cnf. Apparently like with most distributions the mysqld_save startup scripts checks this location for additional configurations and uses that during teh start-up of teh mysql daemon. So I quickly stopped MySQL and issued this command
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
After I started mysql I could find that now the query worked perfectly!
mysql> SHOW STATUS LIKE 'Qcache%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 12253072 |
| Qcache_hits | 2571 |
| Qcache_inserts | 1088 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 36 |
| Qcache_queries_in_cache | 1016 |
| Qcache_total_blocks | 2063 |
+-------------------------+----------+
8 rows in set (0.00 sec)
Cool!! This will speed up operations done on the database!
For more information you can also check
this website.
To speed up functionality in PHP4 it's often know to use a accelerator/bytecode cache. For some weird reason PHP doesn't have/want to have a internal accelerator however there are solutions on the net. I always use
eAccelerator because it is proven for me to be a stable system.
So I downloaded the tar-bal and started to compile...
I assume you are familiar with downloading and uncompressing tar.bz2 files so I won't go into detail here. Once it is uncompressed go into the directory and issue this commands:
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
mkdir /var/eaccelerator
chown www:www /var/eaccelerator
make
make install
The above should all be success full and I assume you have set the correct paths where to find phpize and php-config. Then edit /usr/local/php5/lib/php.ini and add the following lines to the end of the file.
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
Restarts apache and voila, you should be set!
You can check if eAccelerator does run by check phpinfo.
I know the above is a bit quick and dirty HOWTO, bit it should get you started quickly. There are not many pitfalls here I think.
Happy coding!
Ries van Twisk