scalable php design

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
hello,
I know you will probably say "if you need to ask, don't try it", but please do help me.

Any tips/guides etc for building sites that can be very scalable? Upto sevreal hundreds of thousands of visitors a day

(in php/mysql)

Are there any ways to write a script so that while it uses just one database server now, in the future it can be easy to add more than one?

thanks
 
I would recommend that it's better to do it at the server level, with load-balancing/round-robin for distributing server load, and then something like [MySQL] replication for distributed databases. Little point asking your PHP application to do it if you want to be able to switch when the load is too high - as the application is unlikely to be able to respond to the request ;).

I'd say a good principle to follow is storing all your configuration in .ini files or such. That way, if you need to point your application to a different database server, all you need to do is switch/update the ini file that PHP is pointing at.

Other than that, I find that caching is particularly important - output/template caching, data caching (DB requests, XML feed lookups etc). Using a template engine like Smarty means that you don't have to have yor page output generated on-the-fly each time, just serve the static pre-compiled output until a time when you need it updated with fresh data - keeps PHP processing low, and database requests at a minimum = low load = happy servers.

Oh, and also think of flexibility -definitely go for an object-oriented implementation of your app/site. A procedural design isn't going to cut it if you find you need to change the way your code behaves as the volume of requests scales.
 
Last edited:
There are a few areas of PHP you must look into when considering large scale user base.. to start, no sloppyness or code smells. This just comes from good programming and lots, and lots, and lots, and lots of testing, micro testing and unit testing.

The other aspect is items such as persistant connections (connection pools), caching (only recreate the output every 'x' minutes) and so on.

So yes, there are a some considerations to worry about, within PHP, when dealing with large userbase.
 
Back
Top Bottom