Optimize PHP and Accelerate Apache 191
An anonymous reader writes "As the load on an application increases, the bottlenecks in the underlying infrastructure become more apparent in the form of slow response to user requests. This article discusses many of the server configuration items that can make or break an application's performance and focuses on steps you can take to optimize Apache and PHP."
Re:want performance from php? (Score:3, Informative)
running a LAMP Stack w. apache 1.3. The machine serves 6 concurrent users with 8.9 Database-Hits/Sec serving around 30-40G/month.
I have absolutely no problem with apaches speed when it comes to serving pages. It does lag when forking processes, though, so I have to keep a certain quantity of processes in reserve (20).
This leads to memory problems, especially since, with mod_php, the process size alway increases but never decreases with apache-process age. Thrading (where basically memory is shared) and Fastcgi for the php should cure that. And that is what lighty does. But: with apache2, worker mpm and mod_fcgid, it works, too.
Then all you need to do is keep keepaliverequests reasonable and keepalivetimeout low. And get a reverse proxy (apache2.2).
Lighty is probably good, but I do not think it has much advantage over a well tuned apache.
Re:want performance from php? (Score:3, Informative)
Personally I feel Lighttpd is just too light, but I agree, Apache is too heavy. I would love to find a happy medium but I am yet to find a httpd server which even approaches Apache and its popularity shows that an awful lot of people agree with this.
Diet article (Score:5, Informative)
use perl; (Score:1, Informative)
Re:want performance from php? (Score:1, Informative)
One thing lighttpd has going for it is SCGI, FCGI really does need to die.
Apache ain't the fastest... (Score:4, Informative)
For anything SSL related IIS makes fun of Apache.
For many concurrent sessions there are proof of concept servers written in functional languages (like erlang) that handle an order of magnitude (!) more simultaneous sessions than what Apache does.
I understand that for many here Apache is all they know and hence regard it as the holy grail but it is far, far, from being that. It is a good overall purpose web server but it is certainly not the fastest.
In the face of the countless security holes that are all too common in C-written apps I'm now more and more installing pure Java web servers. At first I was using Apache + Tomcat now I'm more and more using Tomcat in standalone mode. Easier configuration, no buffer overflows to patch.
Re:want performance from php? (Score:5, Informative)
Re:You can talk about this all day, but... (Score:5, Informative)
"I also expect that the language is going to be forked at some point unless the PHP developers clean up the function naming - it's infuriating."
There's nothing to stop you from cleaning up the function naming. We'd all appreciate it :-)
Also, if you really want performance "uber alles", don't bother with apache or any other "pre-made" server - write a custom server in c designed to load modules that serve just the content you want served. You can then handle a thousand requests per second (including time to access the database a half-dozen times per request) on comodity hardware.
Its not like there isn't code out there that shows you how to implement a server in c, how to write and load modules in c, how to use threads in c, and how to access mysql via c. You'll be super fast ... except that your development time will be super slow.
apache+php is a compromose that most people can live with, most of the time.
Yes, the function naming in php is crap. Show us a scripting language where it isn't.
Re:want performance from php? (Score:5, Informative)
All that apache does when serving PHP requests with mod_php is run the early phases (auth, URL mapping) and pass the request to PHP. Do you really think that Lighttpd + FastCGI is going to be significantly faster than that? The bottleneck is your PHP code, not the web server.
Lighttpd is probably faster at serving static content. Most sites don't have enough bandwidth to find out.
Careful with the php accelerators (Score:3, Informative)
You also should of course make sure you've got caching happening at every level of your app. Memcached is a great application level cache. Apache side, make sure you enable and configure the memory cache for static files. (mod_mem_cache) and possibly the file cache (mod_disk_cache). Client side, make sure you're caching static files like images, js, css. Apache's mod_expires gives you good control over this in Apache config.
Of course, all of this could be just spinning your wheels if you have badly optimized sql queries or bad table design to start with. Set mysql's slow query log threshold very low to catch these issues early.
Re:Diet article (Score:2, Informative)
Performance tuning and optimization of LAMP (Score:5, Informative)
It includes:
Disclaimer: this is stuff that I have written.
Reverse proxy (Score:3, Informative)
Re:want performance from php? (Score:1, Informative)
Compare the specs: SCGI [python.ca] FCGI [fastcgi.com]
You could probably write a SCGI daemon in your lunch hour.
Re:In the previous article (Score:3, Informative)
Biggest back for the buck... (Score:3, Informative)
It's very easy to do [sufehmi.com], take very little time, reliable & proven (which is not always the case with php accelerators), and will easily drop a double-digit server load to a single one.
It constantly amazes me how people will do the hardest stuff which gave the minimum return first.
Such is life I guess
If you want more proof, read this guy's article [turbochargedcms.com]. He sell a "turbo charged" Wordpress [turbochargedcms.com], got digged and overloaded, optimized his website and still overloaded. Finally his server managed to go through it after he implemented squid's reverse proxy.
In summary - sort out your priorities guys.
Biggest back for the buck first, and then go down from there.