
Are you embarrassed by this number? Me too.
First of all, my post is addressed to those who host many sites on the server. For the rest, it can also be useful, because with it you can quickly add grouping by fragments of the paths of cached files.
You may have allocated too much RAM under the cache. Its size can be significantly reduced by disabling heavyweight but rarely visited sites. I will help you calculate such sites.
I think that there are no more applications and servers that do not use PHP accelerators. One of
two popular accelerators is
XCache . Perhaps someone is using this accelerator, but has not known that for some time it contains a minimalist
admin panel .
')
Admin - a very useful thing, allows you to choose the optimal size of RAM allocated for storing bytecode executable scripts. It also allows you to view stored data and delete it.
The list of scripted scripts looks like a long sausage. The admin has a built-in tool for sorting data, but it’s impossible to work with such a long list.

Add statistics to the regular admin panel
Since the admin is written in open source PHP, we modify it by adding the necessary functionality.

Add to the
PHP List page:
1. Script statistics by host
2. Filter scripts by host (to be exact, by prefix).
xcache.tpl.php line 150
After
foreach (array('Cached' => $cachelist['cache_list'], 'Deleted' => $cachelist['deleted_list']) as $listname => $entries) { $a->reset();
add
if ($listname == 'Cached') { $hosts = array(); $filtertrash = array('', 'usr', 'home'); foreach ($entries as $i => $entry) { if (strpos($entry['name'], $_SERVER['DOCUMENT_ROOT']) === 0) { $host = $_SERVER['DOCUMENT_ROOT']; $prefix = $_SERVER['DOCUMENT_ROOT']; } else { $pos = 0; foreach (explode('/', $entry['name']) as $host) { if (!in_array($host, $filtertrash)) break; $pos += strlen($host) + 1; } $prefix = substr($entry['name'], 0, strpos($entry['name'], $host, $pos) + strlen($host)); } if (isset($hosts[$host])) { $hosts[$host]['files']++; $hosts[$host]['hits'] += $entry['hits']; $hosts[$host]['size'] += $entry['size']; } else { $hosts[$host] = array( 'prefix' => $prefix, 'files' => 1, 'hits' => $entry['hits'], 'size' => $entry['size'], ); } } ?> <table cellspacing="0" cellpadding="4" class="cycles entries"> <tr><th>Host</th><th>Files</th><th>Hits</th><th>Size</th><th>Ratio(size/hits)</th></tr> <?php uasort($hosts, create_function('$a,$b' , 'return $b["size"] - $a["size"];')); foreach ($hosts as $host => $hoststats) { ?><tr><td><a href="?type=0&prefix=<?=$hoststats['prefix']?>"><?=$host?></a></td><td><?=$hoststats['files']?></td><td><?=$hoststats['hits']?></td> <td><?= ($hoststats['size'] > 1048576 ? round($hoststats['size'] / 1048576).' M' : ($hoststats['size'] > 1024 ? round($hoststats['size'] / 1024).' k' : $hoststats['size']) ) ?></td> <td><?=round($hoststats['size']/$hoststats['hits'])?> </tr> <?php } ?> </table> <?php }
Here we cut the host name from the script name or use DOCUMENT_ROOT for chrooted hosts.
All scripts of my sites are in / usr / home / HOST /
For each host count statistics.
The screen below changes the start of the loop in this way. Notice the changed row order.
foreach ($entries as $i => $entry) { $name = htmlspecialchars($entry['name']); if (!empty($_GET['prefix']) && strpos($name, $_GET['prefix']) !== 0) { continue; } echo " <tr ", $a->next(), ">";
This is a table filter by the prefix passed to $ _GET ['prefix']
Result
Update and enjoy host statistics

The most interesting thing in the last column. It primitively calculated the efficiency of occupied memory, based on the size and number of requests.
Most likely, you will see a much greater scatter of values. My table is after the work done, as a result of which I threw away some thick sites without significant attendance.
How to disable caching unnecessary?
If you disable caching, then bytecode will be generated for each script. Still, it will be executed faster than if it worked without an accelerator.
To disable caching, you must set the standard INI variable
xcache.cacher = Off
The following options should be used for individual hosts and files.
1. in php.ini enter the section for each host
[HOST=<host>] xcache.cacher = Off
2. if you have FCGI / FPM / 5.3 +, then put the
.user.ini file in the scripts
folder xcache.cacher = Off
Caching will be disabled for all scripts located in this folder and in all levels below.
3. if you have
apache <IfModule mod_php5.c> php_value xcache.cacher Off </IfModule>
Conclusion
I hope my simple instructions helped you to free up some RAM. Where now to spend it? Well, operatives do not happen much, so it will grow somewhere.
