Wednesday
Jul032013
5 Rockin' Tips for Scaling PHP to 30,000 Concurrent Users Per Server

Jonathan Block, CTO at RockThePost.com, a crowdfunding company, has written a nice set of tips for smaller sites on how to scale a service on EC2 using a small two person development team.
Their service has a typical small scale structure:
- PHP's Zend Framework 2
- Two m1.medium for web servers
- ELB to split the load
- master/slave MySQL database
- Siege for load testing
The very sensible tips that can handle 30,000 concurrent users per web server:
- Use PHP's APC feature. APC is opcode cache that is "really a requirement in order for a website to have a chance at performing well."
- Put everything that's not a .php request on a CDN. Don't serve static files from your web server. They put everything on S3 and use CloudFront as their CDN. Recent CloudFront problems have caused them to serve directly from S3.
- Don't make connections to other servers in your PHP code. Making connections to other servers blocks the server and slows down processing. Use the APC key/value store for data storage and Varnish for caching full pages.
- Use Varnish. Using Varnish mage the single biggest difference to their performance under a load test.
- Use a c1.xlarge. The c1.xlarge has 8 CPUs which really helps under load. The m1.medium has only 1 CPU for processing requests.
Pretty straightforward, yet good advice. The original article has many more details and is well worth reading.
Reader Comments (7)
Interesting. Goes to show how far behind we are. Our current application has around 6 c1.xlarge and 10 fm.medium servers. And it runs pretty slow with about a 100 users. Will read the full article.
But that is just the exterior site. Original article states that once users sign into the site into the 'interior' it only handles 1,000 per server? That's not very much..
Jarrett,
Whats your site?
Jon
I'm shocked to not see PHP-FPM mentioned in this post. Is it so de-facto now that everyone presumes its being used, or (more likely given APC is mentioned) was it overlooked entirely? The performance benefits of PHP-FPM, even within Apache, are astonishing and I'd literally expect a 2x performance boost for all PHP rendered files without any other changes being necessary.
This post about scaling site to 30,000, not about scaling PHP. PHP-FPM can process 350-400 max requests per second on one server
"Don't make connections to other servers in your PHP code.
Making connections to other servers blocks the server and slows down processing. Use the APC key/value store for data storage and Varnish for caching full pages."
Logic pages always need to connect to backend, eg, databases, memcache, or other backend services,
caching is a good ways to improve performance,
but how could you possible serve a page without a backend? many web application are far from been a simple page. hmmm I didn't get it. could anyone explain it?
@reeze: it could be static page!