Created
May 13, 2013 12:04
-
-
Save alixaxel/5567844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function gzip_static($path) | |
{ | |
if ((extension_loaded('zlib') === true) && (is_file($path) === true)) | |
{ | |
$levels = array(); | |
$content = file_get_contents($path); | |
foreach (range(1, 9) as $level) | |
{ | |
$levels[$level] = strlen(gzencode($content, $level)); | |
} | |
if ((count($levels = array_filter($levels)) > 0) && (min($levels) < strlen($content))) | |
{ | |
if (file_put_contents($path . '.gz', gzencode($content, array_search(min($levels), $levels)), LOCK_EX) !== false) | |
{ | |
return touch($path . '.gz', filemtime($path), fileatime($path)); | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment