|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\cache\preloading; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Gives some informations about opcache preloading. |
|
7
|
|
|
* |
|
8
|
|
|
* Ubiquity\cache\preloading$PreloaderCacheInfo |
|
9
|
|
|
* This class is part of Ubiquity |
|
10
|
|
|
* |
|
11
|
|
|
* @author jcheron <[email protected]> |
|
12
|
|
|
* @version 1.0.0 |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
class PreloaderCacheInfo { |
|
16
|
|
|
private static const PRELOAD_KEY_CACHE = 'preload_statistics'; |
|
17
|
|
|
|
|
18
|
|
|
private static function getStatus() { |
|
19
|
|
|
return \opcache_get_status (); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
private static function getElement($part, $default): ?array { |
|
23
|
|
|
return self::getStatus () [self::PRELOAD_KEY_CACHE] [$part] ?? $default; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns true if opcache preloader is activated. |
|
28
|
|
|
* |
|
29
|
|
|
* @return bool |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function isActive(): bool { |
|
32
|
|
|
return \is_array ( self::getStatistics () ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returrns the opcache preload statistics |
|
37
|
|
|
* |
|
38
|
|
|
* @return NULL|array |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function getStatistics(): ?array { |
|
41
|
|
|
return self::getStatus () [self::PRELOAD_KEY_CACHE] ?? null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Returns the preloader memory consumption. |
|
46
|
|
|
* |
|
47
|
|
|
* @return array|NULL |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function getMemoryConsumption(): ?array { |
|
50
|
|
|
return self::getElement ( self::PRELOAD_KEY_CACHE, 0 ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns the list of preloaded functions. |
|
55
|
|
|
* |
|
56
|
|
|
* @return array|NULL |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function getFunctions(): ?array { |
|
59
|
|
|
return self::getElement ( 'functions', [ ] ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the list of preloaded scripts |
|
64
|
|
|
* |
|
65
|
|
|
* @return array|NULL |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function getScripts(): ?array { |
|
68
|
|
|
return self::getElement ( 'scripts', [ ] ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns the list of preloaded classes |
|
73
|
|
|
* |
|
74
|
|
|
* @return array|NULL |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function getClasses(): ?array { |
|
77
|
|
|
return self::getElement ( 'classes', [ ] ); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|