Archive

Archive for the ‘PHP’ Category

Finally a new PHP 5.3.2 snapshot

November 13th, 2009 2 comments

Updated: PHP 5.3.1 (released as of today) has fully functioning support for NTFS junctions.

The PHP Windows team finally bothered to release a new 5.3.2 snapshot after over a week of inactivity:

http://windows.php.net/snapshots/

Sadly, vBulletin 3.8.4′s inlinemod.php still manages to crash it. Stupid unstable snapshots D:

Also I’m running 5.3.2 because some idiot decided it would be smart to drop support for NTFS junctions in PHP 5.3.0 and 5.3.1, while I, like many Windows users, use them to support the www. subdomain.

And I’m running 5.3 because VC9 amongst other things makes PHP 100% faster running vBulletin 3.8 under Windows in my experience.

Categories: PHP, Servers Tags:

DarkCSSCache & DarkJSCache – The best way to compress CSS and JS

November 9th, 2009 1 comment

Download required PHP minify classes

CSS.php:

<?php

	require "class.cssmin.php";

	$prefix = './';
	$files = array("my.css", "another.css");

	$contents = '';
	$size = 0;
	foreach($files as $name){
		$contents .= "\n\n" . file_get_contents($prefix.$name);
		$size += filesize($prefix.$name);
	}

	$contents = "/* DarkCSSCache - 100% Pure Win. */\n".cssmin::minify($contents);

	file_put_contents("../darkcsscache.css", $contents);
	file_put_contents("../darkcsscache.css.gz", gzencode($contents, 9, FORCE_GZIP));
	echo number_format($size)." bytes compressed to...<br />".number_format(strlen($contents))." bytes standard<br />".number_format(filesize("../darkcsscache.css.gz"))." bytes gzipped";
?>

JS.php:

<?php

	require "../class.jsmin.php";

	$prefix = '../';
	$files = array("jquery.js", "shit.js");

	$contents = '';
	$size = 0;
	foreach($files as $name){
		$contents .= "\n\n" . file_get_contents($prefix.$name);
		$size += filesize($prefix.$name);
	}

	$contents = "/* DarkJSCache - 100% Pure Win. */\n".JSMin::minify($contents);

	file_put_contents("../darkjscache.js", $contents);
	file_put_contents("../darkjscache.js.gz", gzencode($contents, 9, FORCE_GZIP));
	echo number_format($size)." bytes compressed to...<br />".number_format(strlen($contents))." bytes standard<br />".number_format(filesize("../darkjscache.js.gz"))." bytes gzipped";
?>

As you might have guessed, this requires nginx with gzip_static to serve the .gz files. A much older version of DarkJSCache exists for Apache – fire me a message/comment if you are interested.

Anyway, this is by far the most efficient way to serve Javascript and CSS concatenated into a single file, minified and GZipped where the user’s browser allows.

It’s also quite unrealistic for a cron script etc. to check dates and update the files. Much better to do it yourself, so you can see changes almost instantly.

Anyway I use this on Imgkk and it’s certainly very successful there.

Categories: PHP, Servers Tags: , ,