Crikey, forgot to include the list.
---------- Forwarded message ----------
From: tamouse mailing lists <tamouse.li...@gmail.com>
Date: Wed, Sep 26, 2012 at 1:57 AM
Subject: Re: [PHP] output compression when host has disabled
mod_deflate, mod_gzip and php_value auto_prepend_file
To: edward eric pedersson <cpsmadn...@googlemail.com>
On Fri, Sep 21, 2012 at 9:50 AM, edward eric pedersson
> without the apache options available I am wondering what other options
> I have. The files are not massive, all but one less than 20k. Not sure
> how much of a performance gain I will get but I thought it is worth
> while asking the question.
> One solution I have on my mind is to call a php script that pulls in
> the css and js files and compresses the output e.g
You need to ensure that the browser you are sending to has the
capability to accept compressed input streams as well. Some don't
still, including some screen readers. This may not be as huge a
consideration with CSS or JS, but should still be considered, I think.
> <link rel="stylesheet" type="text/css"
> // initialize ob_gzhandler function to send and compress data
> ob_start ("ob_gzhandler");
> // send the requisite header information and character set
> header ("content-type: text/css; charset: UTF-8");
> // check cached credentials and reprocess accordingly
> header ("cache-control: must-revalidate");
> // set variable for duration of cached content
> $offset = 60 * 60;
> // set variable specifying format of expiration header
> $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . "
I am pretty sure the header needs to be capitalized: "Expires:". Also,
you can simplify the format string a bit:
$expire = "Expires: " . gmdate (DATE_RFC1123, time() + $offset);
as that is the standard form the Expires header takes.
> // send cache expiration header to the client broswer
> header ($expire);
> //read and echo the file
> $file = readfile($_GET["file"]);
You want to be careful here and validate that you are sending a real
file that contains what *you* want to send. *Always* untaint input.
> echo $file;
> A few questions:
> 1) Will apache cache the full url or the url minus the query parameter?
Generally, it will cache the full url.
> 2) Are there any performance benefits as there is an overhead in
> calling the PHP file?
This entirely depends on the size of the file. If your css or js is
small (<1000 bytes, maybe?) it's not going to be worthwhile. You say
yours are mostly > 20000, so it might very well be worthwhile. Also,
it sort of depends on how heavily your server is loaded. Live
performance tests would probably be worthwhile to guage your
> 3) If the PHP call is cached is it cached with the file query parameter?
Is this a different question than #1?
Something similar was discussed previously, only in the realm of
someone wanting to serve static pages. You can cache the compressed
version of the file and serve if up if it is newer than the
uncompressed version, which might also speed things up, although
probably not a great deal in this case since there's basically no PHP
processing happening here.
p.s. - somehow the OM wound up in my SPAM folder so I didn't see it
for a few days.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php