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\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
|
|
|
public function __construct(Container $container) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($container); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* opcache |
25
|
|
|
* |
26
|
|
|
* @Role anonymous |
27
|
|
|
* @return Stat |
28
|
|
|
*/ |
29
|
|
|
final public function opcache(): Stat |
30
|
|
|
{ |
31
|
|
|
$status = opcache_get_status(); |
32
|
|
|
$this->response->setCode(Response::HTTP_OK)->setContent([ |
33
|
|
|
Response::_ERROR => true, |
34
|
|
|
Response::_ERROR_MSG => 'Opcache disable' |
35
|
|
|
]); |
36
|
|
|
if ($status) { |
|
|
|
|
37
|
|
|
$path = dirname(dirname($this->request->getFilename())); |
38
|
|
|
$scripts = array_filter($status['scripts'], function ($val) use ($path) { |
39
|
|
|
return strpos($val['full_path'], $path) !== false; |
40
|
|
|
}); |
41
|
|
|
$status['scripts'] = array_values($scripts); |
42
|
|
|
$bytes = array_reduce($status['scripts'], function ($stack, $val) { |
43
|
|
|
return $stack + $val['memory_consumption']; |
44
|
|
|
}); |
45
|
|
|
$scriptCount = count($scripts); |
46
|
|
|
unset($scripts); |
47
|
|
|
$this->response |
48
|
|
|
->setCode(Response::HTTP_OK) |
49
|
|
|
->setContent( |
50
|
|
|
[ |
51
|
|
|
'error' => false, |
52
|
|
|
'datas' => [ |
53
|
|
|
'php_version' => phpversion(), |
54
|
|
|
'nb_files' => $scriptCount, |
55
|
|
|
'memory_used' => $bytes, |
56
|
|
|
'status' => $status |
57
|
|
|
] |
58
|
|
|
] |
59
|
|
|
); |
60
|
|
|
unset($scriptCount, $scripts, $bytes); |
61
|
|
|
} |
62
|
|
|
unset($status); |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* filecache |
68
|
|
|
* |
69
|
|
|
* @Role anonymous |
70
|
|
|
* @return Stat |
71
|
|
|
*/ |
72
|
|
|
final public function filecache(): Stat |
73
|
|
|
{ |
74
|
|
|
$path = realpath($this->getCachePath()); |
75
|
|
|
$files = glob($path . '/*'); |
76
|
|
|
$this->response |
77
|
|
|
->setCode(Response::HTTP_OK) |
78
|
|
|
->setContent( |
79
|
|
|
[ |
80
|
|
|
'error' => false, |
81
|
|
|
'datas' => [ |
82
|
|
|
'cache_path' => $path, |
83
|
|
|
'cache_hits' => count($files), |
|
|
|
|
84
|
|
|
'cache_files' => $files, |
85
|
|
|
] |
86
|
|
|
] |
87
|
|
|
); |
88
|
|
|
unset($path, $files); |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.