1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Api\V1; |
4
|
|
|
|
5
|
|
|
use App\Interfaces\Controllers\IApi; |
6
|
|
|
use App\Reuse\Controllers\AbstractApi; |
7
|
|
|
use App\Component\Http\Response; |
8
|
|
|
use App\Container; |
9
|
|
|
|
10
|
|
|
final class Stat extends AbstractApi implements IApi |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* instanciate |
15
|
|
|
* |
16
|
|
|
* @param Container $container |
17
|
|
|
*/ |
18
|
3 |
|
public function __construct(Container $container) |
19
|
|
|
{ |
20
|
3 |
|
parent::__construct($container); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* opcache |
25
|
|
|
* |
26
|
|
|
* @Role anonymous |
27
|
|
|
* @return Stat |
28
|
|
|
*/ |
29
|
1 |
|
final public function opcache(): Stat |
30
|
|
|
{ |
31
|
1 |
|
$this->response |
32
|
1 |
|
->setCode(Response::HTTP_SERVICE_UNAVAILABLE) |
33
|
1 |
|
->setContent([ |
34
|
1 |
|
Response::_ERROR => true, |
35
|
|
|
Response::_ERROR_MSG => 'Opcache disable' |
36
|
|
|
]); |
37
|
1 |
|
$status = opcache_get_status(); |
38
|
1 |
|
if (!empty($status)) { |
39
|
|
|
$path = dirname(dirname($this->request->getFilename())); |
40
|
|
|
$scripts = array_filter($status['scripts'], function ($val) use ($path) { |
41
|
|
|
return strpos($val['full_path'], $path) !== false; |
42
|
|
|
}); |
43
|
|
|
$status['scripts'] = array_values($scripts); |
44
|
|
|
$bytes = array_reduce($status['scripts'], function ($stack, $val) { |
45
|
|
|
return $stack + $val['memory_consumption']; |
46
|
|
|
}); |
47
|
|
|
$scriptCount = count($scripts); |
48
|
|
|
unset($scripts); |
49
|
|
|
$this->response |
50
|
|
|
->setCode(Response::HTTP_OK) |
51
|
|
|
->setContent( |
52
|
|
|
[ |
53
|
|
|
'error' => false, |
54
|
|
|
'datas' => [ |
55
|
|
|
'php_version' => phpversion(), |
56
|
|
|
'nb_files' => $scriptCount, |
57
|
|
|
'memory_used' => $bytes, |
58
|
|
|
'status' => $status |
59
|
|
|
] |
60
|
|
|
] |
61
|
|
|
); |
62
|
|
|
unset($scriptCount, $scripts, $bytes); |
63
|
|
|
} |
64
|
1 |
|
unset($status); |
65
|
1 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* filecache |
70
|
|
|
* |
71
|
|
|
* @Role anonymous |
72
|
|
|
* @return Stat |
73
|
|
|
*/ |
74
|
1 |
|
final public function filecache(): Stat |
75
|
|
|
{ |
76
|
1 |
|
$path = realpath($this->getCachePath()); |
77
|
1 |
|
$files = glob($path . '/*'); |
78
|
1 |
|
$this->response |
79
|
1 |
|
->setCode(Response::HTTP_OK) |
80
|
1 |
|
->setContent( |
81
|
|
|
[ |
82
|
1 |
|
'error' => false, |
83
|
|
|
'datas' => [ |
84
|
1 |
|
'cache_path' => $path, |
85
|
1 |
|
'cache_hits' => count($files), |
|
|
|
|
86
|
1 |
|
'cache_files' => $files, |
87
|
|
|
] |
88
|
|
|
] |
89
|
|
|
); |
90
|
1 |
|
unset($path, $files); |
91
|
1 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|