Projet

Général

Profil

Révision f76c34f5

IDf76c34f5c67227c42e8d07c44fb3bafaab342856
Parent da87fcd6
Enfant 2cbac876

Ajouté par Ricardo Sanz il y a plus de 4 ans

Use APCu functions when available (make plugin compatible with PHP using APCu)

Detect available functions (apc_ or apcu_ ones) and call the right ones.

Voir les différences:

plugins/php/php_apc.php
1 1
<?php
2 2
$ret = array();
3 3

  
4
if(function_exists("apc_cache_info") && function_exists("apc_sma_info"))
4
// Detect APC functions to call.
5
$apc_fn_name = "";
6
if(function_exists("apcu_cache_info") && function_exists("apcu_sma_info"))
7
{
8
  $apc_fn_name = "apcu";
9
} elseif (function_exists("apc_cache_info") && function_exists("apc_sma_info"))
10
{
11
  $apc_fn_name = "apc";
12
}
13

  
14
if(!empty($apc_fn_name))
5 15
{
6 16
  switch ($_GET["act"])
7 17
  {
8 18
    case "memory":
9
      $tmp = apc_sma_info();
19
      $tmp = call_user_func($apc_fn_name . "_sma_info");
10 20
      $ret["mem_used"] = $tmp["seg_size"]-$tmp["avail_mem"];
11 21
      $ret["mem_avail"] = $tmp["avail_mem"];
12 22
      break;
13 23
    case "hits":
14
      $tmp = apc_cache_info();
24
      $tmp =  call_user_func($apc_fn_name . "_cache_info");
15 25
      $ret["num_hits"] = $tmp["num_hits"];
16 26
      $ret["num_misses"] = $tmp["num_misses"];
17 27
      break;
18 28
    case "percents":
19
      $tmp = apc_sma_info();
29
      $tmp =  call_user_func($apc_fn_name . "_sma_info");
20 30
      $ret["memory"] = 100-(($tmp["avail_mem"] / $tmp["seg_size"])*100);
21
      $tmp = apc_cache_info();
31
      $tmp = apcu_cache_info();
22 32
      $ret["hits"] = ($tmp["num_hits"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100;
23 33
      $ret["misses"] = ($tmp["num_misses"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100;
24 34
      break;

Formats disponibles : Unified diff