php 缓存使用监控测试代码。

我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好成都做网站、网站制作服务,我们努力开拓更好的视野,通过不懈的努力,创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,重庆小程序开发,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。
将以下代码存在PHP WEB网站下面,然后通过IE浏览器进行访问。
#cat ocpcache.php
/*
* Fetch configuration and status information from OpCache
*/
$config = opcache_get_configuration();
$status = opcache_get_status();
/*
* Turn bytes into a human readable format
* @param $bytes
*/
function size_for_humans($bytes) {
if ($bytes > 1048576) {
return sprintf("%.2f MB", $bytes/1048576);
} else if ($bytes > 1024) {
return sprintf("%.2f kB", $bytes/1024);
} else return sprintf("%d bytes", $bytes);
}
?>
body{
font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;
margin:auto;
position:relative;
width:1024px;
}
text{
font:10px sans-serif;
}
form{
position: absolute;
right:210px;
top:50px;
}
#graph{
position: absolute;
right:0px;
top:80px;
}
#stats{
position: absolute;
right:234px;
top:240px;
}
tbody tr:nth-child(even) {
background-color:#eee;
}
p.capitalize{
text-transform:capitalize;
}
.tabs{
position:relative;
min-height:200px;
clear:both;
margin:25px 0;
}
.tab{
float:left;
}
.tab label{
background: #eee;
padding:10px;
border:1px solid #ccc;
margin-left:-1px;
position:relative;
left:1px;
}
.tab [type=radio]{
display: none;
}
.content{
position:absolute;
top:28px;
left: 0;
background:white;
padding:20px;
border:1px solid #ccc;
height:500px;
width:480px;
overflow-y:auto;
overflow-x:hidden;
}
.content table {
width:100%;
}
.clickable {
cursor: hand;
cursor: pointer;
}
[type=radio]:checked ~ label{
background: white;
border-bottom:1px solid white;
z-index:2;
}
[type=radio]:checked ~ label ~ .content{
z-index: 1;
}
var hidden = {};
function toggleVisible(head, row) {
if (!hidden[row]) {
d3.selectAll(row)
.transition().style('display', 'none');
hidden[row] = true;
d3.select(head).transition().style('color', '#ccc');
} else {
d3.selectAll(row)
.transition().style('display');
hidden[row] = false;
d3.select(head).transition().style('color', '#000');
}
}
PHP OpCache
foreach($status as $key=>$value) {
if($key=='scripts') continue;
if(is_array($value)) {
foreach($value as $k=>$v) {
if($v===false) $value = "false";
if($v===true) $value = "true";
if($k=='used_memory' || $k=='free_memory' || $k == 'wasted_memory') $v = size_for_humans($v);
if($k=='current_wasted_percentage' || $k=='opcache_hit_rate') $v = number_format($v,2).'%';
if($k=='blacklist_miss_ratio') $v = number_format($v,2);
echo "
\n";
}
continue;
}
if($value===false) $value = "false";
if($value===true) $value = "true";
echo "
\n";
}
?>
foreach($config['directives'] as $key=>$value) {
if($value===false) $value = "false";
if($value===true) $value = "true";
if($key == 'opcache.memory_consumption') $value = size_for_humans($value);
echo "
\n";
}
?>
foreach($status['scripts'] as $key=>$data) {
$dirs[dirname($key)][basename($key)]=$data;
}
asort($dirs);
$id = 1;
foreach($dirs as $dir => $files) {
$count = count($files);
if ($count > 1) {
echo "
";
echo "
";
echo "
";
}
foreach ($files as $file => $data) {
echo "
";
echo "
";
echo "
";
if ($count > 1) {
echo "
";
} else echo "
";
echo "
";
}
++$id;
}
?>
Hits | Memory | Path |
---|
{$dir} ({$count} files) |
---|
{$data["hits"]} | " .size_for_humans($data["memory_consumption"]). " | {$file} | {$dir}/{$file} |
$mem = $status['memory_usage'];
$stats = $status['opcache_statistics'];
$free_keys = $stats['max_cached_keys'] - $stats['num_cached_keys'];
echo <<
var dataset = {
memory: [{$mem['used_memory']},{$mem['free_memory']},{$mem['wasted_memory']}],
keys: [{$stats['num_cached_keys']},{$free_keys},0],
hits: [{$stats['hits']},{$stats['misses']},0]
};
EOB;
?>
var width = 600,
height = 400,
radius = Math.min(width, height) / 2;
var color = d3.scale.category20();
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc()
.innerRadius(radius - 20)
.outerRadius(radius - 50);
var svg = d3.select("#graph").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var path = svg.selectAll("path")
.data(pie(dataset.memory))
.enter().append("path")
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc)
.each(function(d) { this._current = d; }); // store the initial values
d3.selectAll("input").on("change", change);
set_text("memory");
function set_text(t) {
if(t=="memory") {
d3.select("#stats").html(
"
Used | |
"+ "
Free | |
"+ "
Wasted | |
"+ "
| % |
---|
"
);
} else if(t=="keys") {
d3.select("#stats").html(
"
Cached keys | "+dataset[t][0]+" |
"+ "
Free Keys | "+dataset[t][1]+" |
---|
"
);
} else if(t=="hits") {
d3.select("#stats").html(
"
Cache Hits | "+dataset[t][0]+" |
"+ "
Misses | "+dataset[t][1]+" |
---|
"
);
}
}
function change() {
path = path.data(pie(dataset[this.value])); // update the data
path.transition().duration(750).attrTween("d", arcTween); // redraw the arcs
set_text(this.value);
}
function arcTween(a) {
var i = d3.interpolate(this._current, a);
this._current = i(0);
return function(t) {
return arc(i(t));
};
}
附件:http://down.51cto.com/data/2365175
新闻名称:php缓存使用监控测试代码
文章路径:
http://shouzuofang.com/article/gpheoj.html