I’m creating a new web application in PHP and I’d like to create it in a way that scales well over time.
What should or shouldn’t I do? I know that I should cache, but what should I cache and how? What else can I do for the website to remain loading rapidly?
Note: this wasn’t written by me, but by Snorkel from YC news
Here’s a short list:
Varnishor other reverse proxy cache.APCorXCachePHP opcode cache.memcached,redis, file caches, and application-level caches (ie. global vars)Apache,MySQL, andLinuxhave lots of settings that affect performance, especially the timeout settings ought to be turned down.strace,top,iostat,vmstat, and query logging to see which layer is using the most time and resourcesMost of the time a PHP slows down because each PHP process is blocked waiting for I/O from some other layer, either a slow disk, or overloaded database, or hung memcached process, or slow REST API call to a 3rd party service … often just strace’ing a live PHP process will show you what its waiting for … in short, blocking I/O slows down everything. The key to going faster is:
– keep it simple
– cache as much as possible in local memory
– do as few blocking I/O operations as possible per request