栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php 缓存使用监控测试代码

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php 缓存使用监控测试代码

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;

}

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

}

?>

     

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

}

?>

     

HitsMemoryPath
{$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 <<

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229026.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号