Created
April 2, 2014 11:49
-
-
Save GromNaN/9932598 to your computer and use it in GitHub Desktop.
Clear APC on deploy
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 | |
/** | |
* Clear APC opcode and user caches on deploy | |
* per directory and prefix. | |
* | |
* Store this file in your default APACHE/NGINX root (/home/www/apcclearcache.php) | |
* Call this file on deployment: | |
* | |
* php /home/www/apcclearcache.php <release_dir> <user_cache_prefix> | |
* | |
* @author Jérôme TAMARELLE <jerome@tamarelle.net> | |
*/ | |
if ('cli' === PHP_SAPI || in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) | |
{ | |
if ('cli' === PHP_SAPI) | |
{ | |
if (!isset($argv[1])) | |
{ | |
echo "You must specified at least a base directory to clear opcode cache"; | |
exit(0); | |
} | |
$prefix = isset($argv[2]) ? $argv[2] : ''; | |
echo @file_get_contents('http://localhost/apcclearcache.php?prefix='.$prefix.'&dir='.urlencode($argv[1])); | |
} | |
else | |
{ | |
// Remove opcode cache | |
$prefix = $_GET['dir']; | |
$apcInfos = apc_cache_info(); | |
if ($total = count($apcInfos['cache_list'])) | |
{ | |
$count = 0; | |
foreach ($apcInfos['cache_list'] as $item) | |
{ | |
if (0 === strpos($item['filename'], $prefix)) | |
{ | |
apc_delete_file($item['filename']); | |
++$count; | |
} | |
} | |
echo "APC opcode cleared for web ($count items / $total)\n"; | |
} | |
if (empty($_GET['prefix'])) | |
{ | |
return; | |
} | |
// Remove user cache | |
$prefix = $_GET['prefix']; | |
$apcInfos = apc_cache_info('user'); | |
if ($total = count($apcInfos['cache_list'])) | |
{ | |
$count = 0; | |
foreach ($apcInfos['cache_list'] as $item) | |
{ | |
if (0 === strpos($item['info'], $prefix)) | |
{ | |
apc_delete($item['info']); | |
++$count; | |
} | |
} | |
echo "APC user cleared for web ($count items / $total)\n"; | |
} | |
} | |
} | |
else | |
{ | |
echo 'Access denied'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment