Recently in PHP Category

Optimizing SmartOptimizer

| 0 Comments | 0 TrackBacks

Sorry, couldn't wait until 1 year anniversary of last post...

I've been poking around with optimizing my sites' performance over the last few days, and found a real nice tool called SmartOptimizer. SmartOptimizer is acts as a middle-ware between your data and your webserver. When a request is made, .htaccess will pick up, and forward specific file(s) to the optimizer, particularly, images, css, and static HTMLs. This is useful because the optimizer can then compress them using gzip, cache the compressed file, add some http header information to help caching, and serve the compressed optimized file. However, using GTmetrix, I found out that some things are missing, so I decided to add some fixes.

GTmetrix suggested static content should send "Vary: Accept-Encoding" http header, because some public proxies will not cache things properly. And I've found the most effective way to add this is to add the said header in index.php like so:

Find in index.php:

PHP Code
header("Last-Modified: " . $mtimestr);
header("Cache-Control: must-revalidate");

And replace with:

PHP Code
header("Last-Modified: " . $mtimestr);
header("Vary: Accept-Encoding");
header("Cache-Control: must-revalidate");

Another recommendation made was that some files did not had a far enough future expire date. As such, I've modified my index.php to output a further expiry date for most documents. This is not required, and may cause funny caching if your static HTMLs are updated frequently. But, if you want to change it, you may do so like this:

Find in index.php:

PHP Code
if (!$settings['clientCache'] || !$settings['clientCacheCheck'] || !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || $_SERVER['HTTP_IF_MODIFIED_SINCE'] != $mtimestr) {

Add before it:

PHP Code
// 1 year far future expire time:
$now = time();
$mtexpirestr = gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now + 31550600);

Then, find:

PHP Code
header("Last-Modified: " . $mtimestr);
header("Cache-Control: must-revalidate");

*may be different if you did the previous modification.

Replace with:

PHP Code
header("Last-Modified: " . $mtimestr);
header("Expires: " . $mtexpirestr);
header("Cache-Control: must-revalidate");

And that should be it... You get a little bit more caching done on client's end, which hopefully in turn will save you some bandwidth, as well as offer your visitors a snappier browsing experience. Hope this helped!

URL Shortener and Base 62 Encoder / Decoder

| 2 Comments | 0 TrackBacks
I'm creating yet another URL shortener script.  Why?  Because I'm not keen on over paying for simple scripts -- because, well, I'd be over paying -- and I'm not too keen on using open source scripts -- because the more people using the same script, the more likely people will find exploits in it.  So with all that in mind, I set out to create my own script.

About this Archive

This page is an archive of recent entries in the PHP category.

Audiophile is the previous category.

Google Chrome is the next category.

Find recent content on the main index or look in the archives to find all content.