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