Speed up PHP (Advanced)

OP Code Caching

When you excute a php script it has to be compiled and run. If you install a PHP OP Code cache, the code is stored in it’s compiled state so compiling is then skipped for the next page request. This is particularly useful if you have a PHP script that does a lot of calculations or loops.

Speed improvements can range from 40% to over 150%. Installing one is easy so it should be a feature which is used by all PHP programmers.

Here are some of the current contenders that may be of interest : eAccelerator, X-Cache, MemCache, APC

Database Caching

The products above store the compiled state of the PHP, but this does not help us if we have a slow database query. To combat this we store the database results into a file on the local system and call it instead of the database. To make sure the content gets appropriately updated the cache should be regenerate often.

Here is a pseudo code example:

retrieve cache item

if cache item doesn’t exist then

load database results

store cache item

endif

use cache item

You can also check to see how old the cache is : ex : 30 minutes and have it regenerate automatically.

2 Servers are Better than 1

Usually on a web host you will have 1 server processing all the requests (typically Apache). A good way to optimise the setup is a to add an additional “lighter” server to handle requests for static files like : images, javascript, etc … then leave all the heavy requests (parsing of PHP files) to Apache. Now that Apache doesn’t have to waste resourcing on images and other files it will have more resources available for processing.


Other Items of Interest

jMeter – Apache benchmarking tool that records user movement and replicates it.

nGinx – A high performance web server.

Image compression

Found a new tool to compress images online

smushit.com

Apache Webserver

Apache is a very widely used webserver which sends out the pages requested by the user

Links

Apache

It has many modules to extend and add functionality including mod_rewrite that allow you to create search engine ready urls without any Get variables on the end

MySql

Mysql is a widely used database which stores your information in a fast sql database structure

To access and administer the database, you can use packages like

phpmyadmin

sqlbuddy

PHP and Mysql work together well and can expand to huge size tables

Codeigniter

Codeigniter is a very useful PHP Framework which allows for rapid development of websites. We have used Codeigniter for over a year and have found it a great way to build a website quickly using an object orientated paradigm which maximises reuse and structures the code in an MVC design pattern.

Links:

Codeigniter

User Guide

Cheat Sheet

Forum

also visit #codeigniter or irc.freenode.net

Security

Let me start by saying I love CodeIgniter, it’s a developers dream.

Today I plan to talk about some of the security features that are used within my library : Redux Authentication.

Hash Once and Only Once!

Over at TalkPHP someone provided a code snippet which had this code :

$psd = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST['password']))))))));

I’ve made a similar mistake myself in the past.  Someone on the CodeIgniter forums pointed out that a solution like the above will actually increase the probability of a collision. Here’s what inparo had to say :

“It’s safer if you only hash it once.  The initial string is random in both length and characters.  The first sha1 gives you a fixed length and reduced character set.  By hashing this again you’re actually increasing the probability of collisions.”

So there you go folks, hash once. This also leads nicely to my next topic “salts”

Read the rest of this entry »

SEO Directories

Getting links is a very important to improve your website position in search engines.

Check this list of very useful directory links from Info Vilesilencer

   Newer→