Reputation: 6848
How can we handle compression in both? Whose responsibility is it? Which one is better, using apache or php to compress files?
PHP compression code:
ob_start("ob_gzhandler");
Or the apache one:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
Is this right that requests first reach in apache then to PHP? If answer is positive so can we infer that we should use the apache one?
Upvotes: 2
Views: 863
Reputation: 799
In my company we usually use gzip compression on static resources. Apache asks PHP to process those resources (if necessary), then it compresses the output result. I would say that it is faster in theory (C & C++ are faster than PHP) and 'safer' to use Apache compression.
NB: Safer here means that the whole page is going to be compressed while you can forget to compress part of your web page with the ob_start
function.
Upvotes: 3
Reputation: 626
I don't see why any of the two should be faster but do keep in mind that apache can also do the compression for css files/js files... You don't want to parse these files with php to compress them before you deliver them to the browser.
So I would suggest use the apache method.
Upvotes: 3
Reputation:
Well here is what I know, presented in a pros and cons way. Apache:
With PHP, you cannot write everything in once place. There are many other things your .htaccess should have, besides compression:
A charset, expiry/cache control, most likely a few URL re-write rules, permissions, robot(Googlebot etc) specific stuff.
As far as I know, you cannot do all of this solely with PHP, and since you may need to get all of this done, I don't see why you should combine both of them. I have always relied on .htaccess or server level configuration to control the above enumerated aspects, and rarely ever had a problem.
PHP:
Overall, Apache is the winner. That's what I would go with all the time!
Upvotes: 4
Reputation: 3430
Apache is better since it prevents memory limit errors of php and acts faster because of compiled code vs interpreted code in php and also it is more meaningful to do compression in a different layer than php
Upvotes: 2
Reputation: 191729
You would have to run your own tests to see which is faster, but I don't believe there should be any difference in how the content is served. Using PHP, you have to handle the output buffering on your own which may be more difficult. It's more transparent with the apache method.
Upvotes: 2