1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OPCache; |
4
|
|
|
|
5
|
|
|
class OPCacheStatus { |
6
|
|
|
|
7
|
|
|
private $statusData; |
8
|
|
|
private $scripts = array(); |
9
|
|
|
|
10
|
|
|
public function __construct($get_scripts = FALSE) { |
11
|
|
|
$this->statusData = opcache_get_status($get_scripts); |
12
|
|
|
if ($get_scripts && isset($this->statusData['scripts'])) { |
13
|
|
|
$this->scripts = $this->statusData['scripts']; |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function getStatusData() { |
18
|
|
|
return $this->statusData; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getCurrentStatus() { |
22
|
|
|
return array( |
23
|
|
|
'opcache_enabled' => $this->statusData['opcache_enabled'], |
24
|
|
|
'cache_full' => $this->statusData['cache_full'], |
25
|
|
|
'restart_pending' => $this->statusData['restart_pending'], |
26
|
|
|
'restart_in_progress' => $this->statusData['restart_in_progress'], |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getMemoryInfo() { |
31
|
|
|
$memory = $this->getMemoryUsage(); |
32
|
|
|
|
33
|
|
|
return array( |
34
|
|
|
'current_wasted_percentage' => round($memory['current_wasted_percentage'], 2) . '%', |
35
|
|
|
'free_memory' => $this->format($memory['free_memory']), |
36
|
|
|
'used_memory' => $this->format($memory['used_memory']), |
37
|
|
|
'wasted_memory' => $this->format($memory['wasted_memory']), |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getMemoryUsage() { |
42
|
|
|
return $this->statusData['memory_usage']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getStatistics() { |
46
|
|
|
return $this->statusData['opcache_statistics']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getScripts() { |
50
|
|
|
return $this->scripts; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function format($size, $precision = 2) { |
54
|
|
|
$units = array('B', 'KB', 'MB', 'GB'); |
55
|
|
|
$base = log($size) / log(1024); |
56
|
|
|
return round(pow(1024, $base - floor($base)), $precision) . $units[floor($base)]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|