php 快取使用監控測試程式碼

germo發表於2021-09-09

php 快取使用監控測試程式碼。

將以下程式碼存在PHP WEB網站下面,然後透過IE瀏覽器進行訪問。

#cat ocpcache.php

$config = opcache_get_configuration();

$status = opcache_get_status();

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 = phpversion()?> OpCache = $config['version']['version']?>

 

   

   

   

 

 

 

 


   

     

     

     

     

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";

}

?>

     

$k $v
$key $value

     

   


   

     

     

     

     

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";

}

?>

     

$key $value

     

   


   

     

     

     

     

     

       

       

       

     

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));

  };

}

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1868/viewspace-2809530/,如需轉載,請註明出處,否則將追究法律責任。

相關文章