PHP cache uses monitoring test code

Source: Internet
Author: User

The PHP cache uses the monitoring test code.

The following code exists under the PHP Web site and is then accessed through IE browser.

#cat ocpcache.php

<?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&nbsp; MB ", $bytes/1048576);

} else if ($bytes > 1024) {

Return sprintf ("%.2f&nbsp;kb", $bytes/1024);

} else return sprintf ("%d&nbsp;bytes", $bytes);

}

?>

<! DOCTYPE html>

<meta charset= "Utf-8" >

<style>

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;

}

</style>

<script type= "Text/javascript" src= "//cdnjs.cloudflare.com/ajax/libs/d3/3.0.1/d3.v3.min.js" ></script >

<script language= "JavaScript" >

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

}

}

</script>

<body>

<form>

<label><input type= "Radio" name= "DataSet" value= "Memory" checked> memory</label>

<label><input type= "Radio" name= "DataSet" value= "Keys" > Keys</label>

<label><input type= "Radio" name= "DataSet" Value= "hits" > hits</label>

</form>

<div id= "Stats" >

</div>

<div class= "Tabs" >


<div class= "tab" >

<input type= "Radio" id= "Tab-status" name= "Tab-group-1" checked>

<label for= "Tab-status" >Status</label>

<div class= "Content" >

<table>

<?php

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 "<tr><th align=\" left\ "> $k </th><td align=\" right\ "> $v </td></tr>\n";

}

Continue

}

if ($value ===false) $value = "false";

if ($value ===true) $value = "true";

echo "<tr><th align=\" left\ "> $key </th><td align=\" right\ "> $value </td></tr>\n" ;

}

?>

</table>

</div>

</div>


<div class= "tab" >

<input type= "Radio" id= "Tab-config" name= "Tab-group-1" >

<label for= "Tab-config" >Configuration</label>

<div class= "Content" >

<table>

<?php

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 "<tr><th align=\" left\ "> $key </th><td align=\" right\ "> $value </td></tr>\n" ;

}

?>

</table>

</div>

</div>


<div class= "tab" >

<input type= "Radio" id= "tab-scripts" name= "Tab-group-1" >

<label for= "tab-scripts" >scripts (<?=count ($status ["Scripts"]);?>) </label>

<div class= "Content" >

<table style= "FONT-SIZE:0.8EM;" >

<tr>

<th width= "10%" >Hits</th>

<th width= "20%" >Memory</th>

<th width= "70%" >Path</th>

</tr>

<?php

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

echo "<th class=\" clickable\ "id=\" head-{$id}\ "colspan=\" 3\ "' #row-{$id} ') \" >{$dir} ({$count} files) </th > ";

echo "</tr>";

}

foreach ($files as $file = = $data) {

echo "<tr id=\" row-{$id}\ ">";

echo "<td>{$data [" hits "]}</td>";

echo "<td>". Size_for_humans ($data ["memory_consumption"]). "</td>";

if ($count > 1) {

echo "<td>{$file}</td>";

} else echo "<td>{$dir}/{$file}</td>";

echo "</tr>";

}

+ + $id;

}

?>

</table>

</div>

</div>


</div>


<div id= "graph" >

</div>

<?php

$mem = $status [' Memory_usage '];

$stats = $status [' Opcache_statistics '];

$free _keys = $stats [' Max_cached_keys ']-$stats [' Num_cached_keys '];

Echo <<<eob

<script>

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 (

"<table><tr><th style= ' background: #1f77b4; ' Align=right>used</th><td align=right> <?php Echo Size_for_humans ($mem [' used_memory '])?></td></tr> "+

"<tr><th style= ' background: #aec7e8; ' Align=right>free</th><td align=right><?php Echo Size_for_humans ($mem [' free_memory '])?></td></tr> "+

"<tr><th style= ' background: #ff7f0e; ' Align=right>wasted</th><td align=right><?php Echo Size_for_humans ($mem [' wasted_memory '])?></td></tr> "+

"<tr><th style= ' background: #ff7f0e; ' > </th><td align=right><?php echo number_format ($mem [' Current_wasted_percentage '],2)? >%</ Td></tr></table> "

);

} else if (t== "keys") {

D3.select ("#stats"). HTML (

"<table><tr><th style= ' background: #1f77b4; ' >cached keys</th><td align=right> "+dataset[t][0]+" </td></tr> "+

"<tr><th style= ' background: #aec7e8; ' >free keys</th><td align=right> "+dataset[t][1]+" </td></tr></table> "

);

} else if (t== "hits") {

D3.select ("#stats"). HTML (

"<table><tr><th style= ' background: #1f77b4; ' Align=right>cache hits</th><td align=right > "+dataset[t][0]+" </td></tr> "+

"<tr><th style= ' background: #aec7e8; ' Align=right>misses</th><td align=right>" +dataset[t][ 1]+ "</td></tr></table>"

);

}

}

function Change () {

Path = Path.data (Pie (dataset[this.value)); Update the data

Path.transition (). Duration (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));

};

}

</script>

</body>

This article is from the "Spin Wood Technology Blog" blog, please be sure to keep this source http://mrxiong.blog.51cto.com/287318/1587593

PHP cache uses monitoring test code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.