Only the important functions implemented… might be of use to someone else migrating lazily from APC to XCache.
Best used via auto_prepend_file in php.ini.
<?php
if(!function_exists('apc_store')){
function apc_store($key, $var, $ttl = 0){
return xcache_set($key, $var, $ttl);
}
}
if(!function_exists('apc_fetch')){
function apc_fetch($key, &$success=true){
$success = xcache_isset($key);
return xcache_get($key);
}
}
if(!function_exists('apc_delete')){
function apc_delete($key){
return xcache_unset($key);
}
}
if(!function_exists('apc_exists')){
function apc_exists($keys){
if(is_array($keys)){
$exists = array();
foreach($keys as $key){
if(xcache_isset($key))
$exists[]=$key;
}
return $exists;
}
return xcache_isset($keys);
}
}
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.
Nginx is a beast of a webserver so you can actually do something like this and receive replies with 0ms delay in between (unfortunately ping is a factor :< )
Also graphs coming soon, but I still find the native format useful and quite readable with it updating several times a second.
Requirements:
<html>
<head>
<script src='jquery.js'></script>
<script>
var fresh = 0;
var doIt = function(){
$.ajax({
url: "/nginx_status",
type: "GET",
dataType: "text",
success: function(data, textStatus){
lol.textContent = data;
doIt();
}
});
fresh ++;
ref.textContent = fresh;
};
</script>
</head>
<body onload="var lol = document.getElementById('lol');var ref = document.getElementById('ref');doIt()">
<pre>Nginx Live Status
By Darkimmortal
Refreshes: <span id='ref'></span>
---------------------------------------------------------------
<span id='lol'></span>---------------------------------------------------------------
</body>
</html>
Also you obviously need this in your nginx config somewhere:
location /nginx_status {
stub_status on;
access_log off;
}